public static SimaLandApiException FromError(ErrorResponse errorResponse) { if (errorResponse == null) { throw new ArgumentNullException(nameof(errorResponse)); } string message = $"{errorResponse.Status} {errorResponse.Code} {errorResponse.Detail}"; var exception = new SimaLandApiException(errorResponse, message); return(exception); }
public static async ValueTask EnsureSuccessAsync(this HttpResponseMessage httpResponseMessage) { if (httpResponseMessage == null) { throw new ArgumentNullException(nameof(httpResponseMessage)); } if (httpResponseMessage.IsSuccessStatusCode) { return; } var httpContent = httpResponseMessage.Content; if (!httpContent.ContentTypeIs(ErrorContentType)) { httpResponseMessage.EnsureSuccessStatusCode(); } var errorResponse = await httpContent.ReadJsonAsync <ErrorResponse>(); throw SimaLandApiException.FromError(errorResponse); }