diff --git a/src/ReC.Client/ReCApiException.cs b/src/ReC.Client/ReCApiException.cs new file mode 100644 index 0000000..16258f1 --- /dev/null +++ b/src/ReC.Client/ReCApiException.cs @@ -0,0 +1,88 @@ +using System; +using System.Net; +using System.Net.Http; + +namespace ReC.Client +{ + /// + /// Represents an error returned by the ReC API. + /// +#if !NETFRAMEWORK + [Serializable] +#endif + public class ReCApiException : Exception + { + /// + /// The HTTP status code returned by the API. + /// + public HttpStatusCode StatusCode { get; } + + /// + /// The HTTP reason phrase returned by the API, if any. + /// +#if NETFRAMEWORK + public string ReasonPhrase { get; } +#else + public string? ReasonPhrase { get; } +#endif + + /// + /// The raw response body returned by the API, if any. + /// +#if NETFRAMEWORK + public string ResponseBody { get; } +#else + public string? ResponseBody { get; } +#endif + + /// + /// The HTTP method used for the failed request. + /// +#if NETFRAMEWORK + public string Method { get; } +#else + public string? Method { get; } +#endif + + /// + /// The request URI that was called. + /// +#if NETFRAMEWORK + public Uri RequestUri { get; } +#else + public Uri? RequestUri { get; } +#endif + + /// + /// Initializes a new instance of the class. + /// + /// A summary message describing the error. + /// The HTTP status code returned by the API. + /// The HTTP reason phrase returned by the API. + /// The raw response body returned by the API. + /// The HTTP method used for the request. + /// The request URI that was called. + public ReCApiException( + string message, + HttpStatusCode statusCode, +#if NETFRAMEWORK + string reasonPhrase, + string responseBody, + string method, + Uri requestUri +#else + string? reasonPhrase, + string? responseBody, + string? method, + Uri? requestUri +#endif + ) : base(message) + { + StatusCode = statusCode; + ReasonPhrase = reasonPhrase; + ResponseBody = responseBody; + Method = method; + RequestUri = requestUri; + } + } +}