public async Task GetNotFoundTestServerHandlesErrorMessageContainsRequest( SampleServerFactory serverFactory, string uri) { using (var server = serverFactory.Create()) { using (var flurlClient = new FlurlClient()) { flurlClient.Settings.HttpClientFactory = new OwinTestHttpClientFactory(server); flurlClient.BaseUrl = "http://localhost"; try { var json = await flurlClient.Request(uri).GetJsonAsync(); } catch (FlurlHttpException exception) { var response = exception.Call?.Response; if (response == null) { throw; } var throwException = await Assert.ThrowsAsync <Exception>(() => response.HandleErrors(throwOnUnhandledResponses: false)); Assert.True(throwException.Message.Contains("Request")); } } } }
public async Task UnknownResponseExceptionContainsResponse( SampleServerFactory serverFactory) { using (var server = serverFactory.Create()) { var response = await server.HttpClient.GetAsync("/foo"); var exception = await Assert.ThrowsAsync <Exception>(() => response.HandleErrors()); Assert.True(exception.Message.Contains("Response")); } }