Interface IApiException
Defines the contract for API exception handling within the Xperiflow system.
Namespace: Workspace.XBR.Xperiflow.Core.RestApi.Exceptions
Assembly: Xperiflow.dll
public interface IApiException
Examples
// Example usage in exception handling
try
{
var result = await apiClient.GetDataAsync();
}
catch (IApiException apiEx)
`{
Console.WriteLine($"API Error: Status {apiEx.StatusCode}`");
Console.WriteLine($"Response: {apiEx.Response}");
// Handle the exception using the standardized handler
throw apiEx.Handle();
}
Remarks
This interface provides a standardized way to handle HTTP API exceptions, capturing essential information about the failure including status codes, response headers, and response content.
Implementations of this interface should provide detailed error information that can be used for debugging, logging, and presenting meaningful error messages to users.
Properties
Headers
Gets the HTTP response headers associated with the failed API request.
IReadOnlyDictionary<string, IEnumerable<string>> Headers { get; }
Remarks
These headers can provide additional context about the API failure, including rate limiting information, server details, and other diagnostic information.
Response
Gets the raw HTTP response body content from the failed API request.
string? Response { get; }
Remarks
This typically contains detailed error information from the API, including error codes, messages, and additional context that can be used for debugging and error reporting.
StatusCode
Gets the HTTP status code returned by the failed API request.
int StatusCode { get; }
Remarks
This status code indicates the type of failure that occurred:
-
4xx codes indicate client errors (bad request, unauthorized, etc.)
-
5xx codes indicate server errors (internal server error, bad gateway, etc.)
Methods
Handle()
Handles the API exception by converting it to an appropriate system exception.
Exception Handle()
Remarks
This method should transform the API exception into a form that's appropriate for the application's error handling system, including proper logging and user-friendly error messages.
Returns
System.Exception
A system exception that can be thrown to propagate the error through the application with proper logging and error handling.
ToString()
Returns a string representation of the API exception including response details.
string ToString()
Remarks
This method provides a detailed string representation that includes both the HTTP response content and the standard exception information, making it useful for logging and debugging purposes.
Returns
System.String
A formatted string containing the exception details, including the HTTP response and standard exception information.