Add ReCApiException class for API error handling

A new `ReCApiException` class was introduced in the `ReC.Client` namespace to represent errors returned by the ReC API.

The class includes properties for detailed error information:
- `StatusCode`, `ReasonPhrase`, `ResponseBody`, `Method`, and `RequestUri`.

A constructor was added to initialize these properties. Conditional compilation directives ensure compatibility between .NET Framework and other .NET targets. The class is marked as `[Serializable]` for non-.NET Framework targets.
This commit is contained in:
2026-05-19 18:56:43 +02:00
parent 992395dec3
commit 71defc0e4c

View File

@@ -0,0 +1,88 @@
using System;
using System.Net;
using System.Net.Http;
namespace ReC.Client
{
/// <summary>
/// Represents an error returned by the ReC API.
/// </summary>
#if !NETFRAMEWORK
[Serializable]
#endif
public class ReCApiException : Exception
{
/// <summary>
/// The HTTP status code returned by the API.
/// </summary>
public HttpStatusCode StatusCode { get; }
/// <summary>
/// The HTTP reason phrase returned by the API, if any.
/// </summary>
#if NETFRAMEWORK
public string ReasonPhrase { get; }
#else
public string? ReasonPhrase { get; }
#endif
/// <summary>
/// The raw response body returned by the API, if any.
/// </summary>
#if NETFRAMEWORK
public string ResponseBody { get; }
#else
public string? ResponseBody { get; }
#endif
/// <summary>
/// The HTTP method used for the failed request.
/// </summary>
#if NETFRAMEWORK
public string Method { get; }
#else
public string? Method { get; }
#endif
/// <summary>
/// The request URI that was called.
/// </summary>
#if NETFRAMEWORK
public Uri RequestUri { get; }
#else
public Uri? RequestUri { get; }
#endif
/// <summary>
/// Initializes a new instance of the <see cref="ReCApiException"/> class.
/// </summary>
/// <param name="message">A summary message describing the error.</param>
/// <param name="statusCode">The HTTP status code returned by the API.</param>
/// <param name="reasonPhrase">The HTTP reason phrase returned by the API.</param>
/// <param name="responseBody">The raw response body returned by the API.</param>
/// <param name="method">The HTTP method used for the request.</param>
/// <param name="requestUri">The request URI that was called.</param>
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;
}
}
}