feat(network): enable HTTP error validation in Ktor HttpClient#122
Open
therajanmaurya wants to merge 1 commit intodevfrom
Open
feat(network): enable HTTP error validation in Ktor HttpClient#122therajanmaurya wants to merge 1 commit intodevfrom
therajanmaurya wants to merge 1 commit intodevfrom
Conversation
Add `expectSuccess = true` to the default HttpClient configuration. This enables Ktor's response validation which throws: - ClientRequestException for 4xx responses - ServerResponseException for 5xx responses Without this, non-2xx responses are silently returned as successful, making proper error handling impossible. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
niyajali
requested changes
Feb 17, 2026
| install(ContentNegotiation) { | ||
| json(jsonConfig) | ||
| } | ||
|
|
Collaborator
There was a problem hiding this comment.
To prevent application crashes when the API fails for reasons such as network issues or server problems, we must implement client-side error handling, preferably by using a try-catch block or a custom interceptor or a sealed interface/class with custom errors data classes with serializable fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
expectSuccess = trueto the default HttpClient configurationChanges
ClientRequestExceptionis thrown for 4xx responsesServerResponseExceptionis thrown for 5xx responsesWhy
Without this setting, non-2xx responses are silently returned as successful responses, making proper error handling impossible. The response body would be attempted to be parsed as the success type, often leading to confusing deserialization errors instead of proper HTTP error handling.
Test plan
ClientRequestExceptionServerResponseException🤖 Generated with Claude Code