C# Client Library
A C# Client Library for the AnalyzeRe REST API
APIRequestException.cs
Go to the documentation of this file.
1 using System;
2 
3 using AnalyzeRe.APITypes;
4 using RestSharp;
5 
6 namespace AnalyzeRe
7 {
14  [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
15  "CA2237:MarkISerializableTypesWithSerializable")]
16  public class APIRequestException : Exception
17  {
19  public IRestResponse RestResponse { get; set; }
20 
23  public ServerError ServerError { get; set; }
24 
27  public IRestRequest Request => RestResponse?.Request;
28 
38  string message,
39  Exception innerException = null,
40  IRestResponse restResponse = null,
41  ServerError serverError = null)
42  : base(message, innerException)
43  {
44  ServerError = serverError;
45  RestResponse = restResponse;
46  }
47 
51  public override string ToString()
52  {
53  return "APIRequestException.RestResponse: " + (RestResponse == null ?
54  "(null)" : Indent("\n" + RestResponse.PrettyPrint())) +
55  "\nAPIRequestException.ServerError: " + (ServerError == null ?
56  "(null)" : Indent("\n" + ServerError)) +
57  "\nAPIRequestException.Base Exception:" + Indent("\n" + base.ToString());
58  }
59 
60  // Used to build a pretty ToString from exception sub-properties.
61  private static string Indent(object toConvertToString)
62  {
63  return toConvertToString.ToString().Replace("\n", "\n ");
64  }
65  }
66 }
override string ToString()
Creates and returns a string representation of the current exception that includes a summary of the R...
APIRequestException(string message, Exception innerException=null, IRestResponse restResponse=null, ServerError serverError=null)
Construct a new APIRequestException.
IRestResponse RestResponse
The IRestResponse that generated this exception.
A custom exception class that includes the RestSharp.IRestResponse that generated the exception...
Used to deserialize server error messages.
Definition: ServerError.cs:8
IRestRequest Request
The original request object (obtained via the IRestResponse.Request property)