Override exceptions from the http client with a feature?
See original GitHub issueI haven’t been able to find a way to override the BadResponseStatusException
with a ktor feature. My team has previously overridden exceptions to a common format so that they are easier to handle. We also don’t like to leak the HttpClient
code into the entire application, but instead like to create a service module, where it’s completely encapsulated from the rest of the application.
We’ve tried a number of ways to override the exception using features, but nothing has quite worked as we’ve expected. If this is currently possible, can you please indicate how this can be done, otherwise please add this as a feature request.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:5 (3 by maintainers)
Top Results From Across the Web
HttpClient exception handling guide
HttpException represents an abstract logical error in HttpClient. Generally this kind of exception cannot be automatically recovered from. org.apache.commons.
Read more >How to override a method when using httpclient? What else is ...
We are using httpclient to connect with a website where there are a lot of redirects. After we tested our initial implementation, ...
Read more >Handling Exceptions Using the Angular HttpClient Service
We will discuss some of the best ways to manage HTTP exceptions within your app while using Angular's HttpClient service.
Read more >Exception Handling in ASP.NET Web API - Microsoft Learn
Describes ASP.NET Web API executes error and exception handling and provides examples for errors and exceptions.
Read more >Handling Errors - FastAPI
When a request contains invalid data, FastAPI internally raises a RequestValidationError . And it also includes a default exception handler for it. To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@e5l Doesn’t work. If we look at https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-core/common/src/io/ktor/client/call/HttpClientCall.kt#L54-L62 the problem is that all exceptions that aren’t
BadResponseStatusException
are overridden.I added:
And also:
My result is:
The fix in
master
. SeeHttpResponseValidator
feature for the details.