[PR #3186] Improve http error codes #10560

Closed
opened 2026-02-16 18:15:15 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/3186

State: closed
Merged: Yes


This PR refactors error handling in the Opencode server and storage modules to use more appropriate HTTP status.

Key changes:

  • Adds HTTP status code support to NamedError and updates error responses to use correct codes (400, 404, 500).
  • 500 (Internal Server Error) is now used instead of 400 (Bad Request) for unknown errors
  • Implements NotFoundError in storage operations, returning 404 when resources are missing.
  • Adds httpCode field to NamedError, so the proper HTTP status code can be assigned to each error at time of definition (falling back to 500)
  • Updates OpenAPI spec to document new error responses.
  • Ensures ModelNotFoundError uses status 400.

Example payload:

{
  "name": "NotFoundError",
  "data": {
    "message": "Resource not found: /home/haris/.local/share/opencode/storage/session/ea2235cd982d8eaa572f68a5f2537637b1d1a2c2/ses_a.json"
  }
}

Closes #3135.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/3186 **State:** closed **Merged:** Yes --- This PR refactors error handling in the Opencode server and storage modules to use more appropriate HTTP status. Key changes: - ~Adds HTTP status code support to NamedError and~ updates error responses to use correct codes (400, 404, 500). - 500 (Internal Server Error) is now used instead of 400 (Bad Request) for unknown errors - Implements NotFoundError in storage operations, returning 404 when resources are missing. - ~Adds httpCode field to NamedError, so the proper HTTP status code can be assigned to each error at time of definition (falling back to 500)~ - Updates OpenAPI spec to document new error responses. - Ensures ModelNotFoundError uses status 400. Example payload: ```json { "name": "NotFoundError", "data": { "message": "Resource not found: /home/haris/.local/share/opencode/storage/session/ea2235cd982d8eaa572f68a5f2537637b1d1a2c2/ses_a.json" } } ``` Closes #3135.
yindo added the pull-request label 2026-02-16 18:15:15 -05:00
yindo closed this issue 2026-02-16 18:15:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10560