Skip to content

[Ktor] HttpException: fall back to default reason phrase#141

Merged
rfc2822 merged 2 commits intomainfrom
140-httpexception-fall-back-to-default-reason-phrase-for-message
Dec 11, 2025
Merged

[Ktor] HttpException: fall back to default reason phrase#141
rfc2822 merged 2 commits intomainfrom
140-httpexception-fall-back-to-default-reason-phrase-for-message

Conversation

@rfc2822
Copy link
Member

@rfc2822 rfc2822 commented Dec 11, 2025

If there's no HTTP reason prhase (like for HTTP/2), this PR changes HttpException to fall back to a default reason phrase for the respective status code.

Previously, a HttpException for HTTP/2 403 had the message: HTTP 403.

Now it has HTTP 403 Forbidden as one would expect.

- Change message format to include reason phrase
- Add `reasonPhrase` function to determine the reason phrase for a given HTTP status
@rfc2822 rfc2822 linked an issue Dec 11, 2025 that may be closed by this pull request
@rfc2822 rfc2822 self-assigned this Dec 11, 2025
@rfc2822 rfc2822 requested a review from Copilot December 11, 2025 14:03
@rfc2822 rfc2822 marked this pull request as ready for review December 11, 2025 14:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances HttpException to include HTTP reason phrases in error messages, with a fallback mechanism for protocols like HTTP/2 that don't provide them. The change improves error message clarity by transforming messages from "HTTP 403" to "HTTP 403 Forbidden".

  • Adds a reasonPhrase() helper method that extracts the status description or falls back to the default phrase for standard status codes
  • Updates the exception message format to include both the status code value and its description
  • Adds comprehensive test coverage for the new functionality

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main/kotlin/at/bitfire/dav4jvm/ktor/exception/HttpException.kt Implements the reasonPhrase() method and updates the message construction to use it
src/test/kotlin/at/bitfire/dav4jvm/ktor/exception/HttpExceptionTest.kt Adds tests for the message format and reasonPhrase() method with both empty and custom descriptions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rfc2822
Copy link
Member Author

rfc2822 commented Dec 11, 2025

Works for bitfireAT/davx5-ose#1878, so merging

@rfc2822 rfc2822 merged commit 57321c9 into main Dec 11, 2025
11 checks passed
@rfc2822 rfc2822 deleted the 140-httpexception-fall-back-to-default-reason-phrase-for-message branch December 11, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Ktor] HttpException: fall back to default reason phrase for message

2 participants