public void Create_HttpStatusCode_ShouldBeSetToPassedValue() { var expectedStatusCode = 500; var exception = PinSharpException.Create <MockException>(null, null, null, expectedStatusCode); exception.HttpStatusCode.Should().Be(expectedStatusCode); }
public void Create_HttpStatusCode_NullValueShouldNotOverwriteExceptionValue() { var expectedStatusCode = MockException.DefaultStatusCode; var exception = PinSharpException.Create <MockException>(null, null, null, null); exception.HttpStatusCode.Should().Be(expectedStatusCode); }
private static async Task <Exception> CreateException(HttpResponseMessage response) { var url = response.RequestMessage.RequestUri.ToString(); var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var error = await response.Content.ReadAsAsync <ErrorResponse>().ConfigureAwait(false); var message = error.Message; var status = (int)response.StatusCode; switch (status) { case 400: return(PinSharpException.Create <PinSharpBadRequestException>(message, url, content)); case 401: return(PinSharpException.Create <PinSharpAuthorizationException>(message, url, content)); case 403: return(PinSharpException.Create <PinSharpForbiddenException>(message, url, content)); case 404: return(PinSharpException.Create <PinSharpNotFoundException>(message, url, content)); case 408: return(PinSharpException.Create <PinSharpTimeoutException>(message, url, content)); case 429: return(PinSharpException.Create <PinSharpRateLimitExceededException>(message, url, content, 429)); case 500: case 502: case 599: return(PinSharpException.Create <PinSharpServerErrorException>(message, url, content, status)); default: return(new PinSharpException(message) { RequestUrl = url, ResponseContent = content, HttpStatusCode = status }); } }