Skip to main content

HttpResponseExtensionMethods

A static class in Alta.Api.DataTransferModels, Alta.Api.DataTransferModels.Extensions.

Turns API responses into results or exceptions, and logs them.

Fields​

2 private and internal fields
MemberWhat it is
private static readonly Logger LoggerClass logger.
private const string RequestIdHeaderResponse header that carries the API's request id, X-Request-Id.

Methods​

MemberWhat it is
static async Task<Exception> HandleForbiddenOrOtherHttpStatus(HttpResponseMessage response)Logs a failed response and returns a ForbiddenException for 403 or an HttpException for anything else.
static async Task<T> HandleResponse<T>(HttpResponseMessage response)Returns the body as T on success, otherwise throws an ApiErrorException (400) or the exception from HandleForbiddenOrOtherHttpStatus.
static async Task LogDebugResponse(HttpResponseMessage response)Writes the method, URI, headers, body and request id to the debug log.
static async Task LogErrorResponse(HttpResponseMessage response)Writes the method, URI, headers, body and request id to the error log.
1 private and internal method
MemberWhat it is
private static async Task<ApiErrorException> CreateApiErrorExceptionAsync(HttpResponseMessage response)Reads a 400 body as an ApiError and wraps it in an ApiErrorException; unreadable bodies become an UnspecifiedError.