Skip to content

Consistently use constants for HTTP status codes#964

Merged
Avery-Dunn merged 1 commit intoavdunn/retry-behaviorfrom
avdunn/status-code-constants
Jun 4, 2025
Merged

Consistently use constants for HTTP status codes#964
Avery-Dunn merged 1 commit intoavdunn/retry-behaviorfrom
avdunn/status-code-constants

Conversation

@Avery-Dunn
Copy link
Contributor

@Avery-Dunn Avery-Dunn commented Jun 4, 2025

The changes in #960 made it clear that the library is inconsistent when it comes to HTTP status codes: not all codes had a constant, and even when there was a constant it often wasn't used.

This PR adjusts the HttpStatus enum introduced in #960 to be a simpler class of constants and helper methods, and refactors every status code reference to use these constants.

This is a separate PR in order to be much easier to review, each individual change is minor and they should not affect any existing behavior.

The status code constants follow the style in HttpURLConnection, a standard Java package that also has these sorts of constants: https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html

However, I didn't want to rely on that since we only need a small subset and none of the other code, plus this allows us to add custom helper methods (like the isServerError() that checks for 5xx errors)

@Avery-Dunn Avery-Dunn requested a review from a team as a code owner June 4, 2025 00:37
@Avery-Dunn Avery-Dunn merged commit b0afc5d into avdunn/retry-behavior Jun 4, 2025
3 checks passed
@Avery-Dunn Avery-Dunn deleted the avdunn/status-code-constants branch June 5, 2025 15:34
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.

2 participants