Skip to content

fix: use 400 Bad Request for expired passcode instead of 408#2402

Closed
jaffarkeikei wants to merge 1 commit intoteamhanko:mainfrom
jaffarkeikei:fix/passcode-expired-status-code
Closed

fix: use 400 Bad Request for expired passcode instead of 408#2402
jaffarkeikei wants to merge 1 commit intoteamhanko:mainfrom
jaffarkeikei:fix/passcode-expired-status-code

Conversation

@jaffarkeikei
Copy link
Copy Markdown
Contributor

@jaffarkeikei jaffarkeikei commented Jan 29, 2026

Resolves #2398

Summary

Changed HTTP status code from 408 (Request Timeout) to 400 (Bad Request) for expired passcodes.

Changes

  • Status: http.StatusRequestTimeouthttp.StatusBadRequest
  • Message: "passcode request timed out" → "passcode has expired"
  • Removed TODO comment

Why?

HTTP 408 is for network/client timeouts, not application validation failures. Using 400 prevents clients from auto-retrying and correctly indicates a client error.

Impact

  • ✅ Better HTTP semantics (aligns with RFC 7231)
  • ✅ No automatic retries from HTTP clients
  • ✅ Clearer error handling

Resolves teamhanko#2398

## Summary
Changed HTTP status code from 408 (Request Timeout) to 400 (Bad Request)
when a passcode has expired. This better aligns with HTTP semantics and
the actual error condition.

## Changes
- Changed status code from `http.StatusRequestTimeout` (408) to
  `http.StatusBadRequest` (400) in passcode.go
- Updated error message from "passcode request timed out" to
  "passcode has expired" for clarity
- Removed TODO comment as the issue has been resolved

## Rationale

HTTP 408 (Request Timeout) is meant for situations where:
- The client took too long to send the request
- The server timed out waiting for request data
- Network/connection issues caused timeouts

HTTP 400 (Bad Request) is appropriate when:
- Client sends invalid or expired data (like an expired passcode)
- Application-level validation fails
- Business logic determines request is malformed

## Impact
- Prevents HTTP clients from auto-retrying (which they often do for 408s)
- Improves monitoring accuracy (408s typically indicate infrastructure
  issues, not validation failures)
- Aligns with RFC 7231 HTTP status code semantics
- Better API ergonomics for API consumers

## References
- RFC 7231: https://tools.ietf.org/html/rfc7231#section-6.5.1
@lfleischmann
Copy link
Copy Markdown
Member

Won't do. Old API endpoints are already marked deprecated and slated for removal in the near future. Closing this PR.

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.

Incorrect HTTP status code for expired passcode (408 instead of 400/422)

2 participants