Skip to content

fix(api-express-router): honour errorStatusCode and JSON error envelope in default adapter#2720

Open
goastler wants to merge 5 commits into
mainfrom
fix/provider-admin-error-status
Open

fix(api-express-router): honour errorStatusCode and JSON error envelope in default adapter#2720
goastler wants to merge 5 commits into
mainfrom
fix/provider-admin-error-status

Conversation

@goastler

Copy link
Copy Markdown
Member

What

In the default endpoint adapter's catch block, surface ProsopoBaseErrors with their own status code via unwrapError (standard { error: jsonError } envelope), and fall back to the constructor-supplied errorStatusCode (as JSON) for unexpected errors — instead of the hardcoded status(500).send("An internal server error occurred.").

Why

The hardcoded 500 + plain-text body ignored the adapter's errorStatusCode (set to 400 for the admin router in startProviderApi.ts ~L310) and broke the { error: ... } JSON envelope used by every other route, so admin client errors surfaced as 500 plain text.

File: packages/api-express-router/src/endpointAdapter/apiExpressDefaultEndpointAdapter.ts (~L54-80)

Verification

npm run -w @prosopo/api-express-router build:tsc yields the same 57 pre-existing errors with and without this change; the only error touching the edited file is a pre-existing Cannot find module '@prosopo/logger' (project-reference build artifacts are absent in this checkout). No new type errors introduced.

goastler added 2 commits June 18, 2026 00:47
…adapter

The default endpoint adapter catch block hardcoded
response.status(500).send("An internal server error occurred."),
ignoring the constructor's errorStatusCode (400 for the admin router) and
breaking the { error: ... } JSON envelope used by every other route.

ProsopoBaseErrors now surface their own status code via unwrapError with
the standard { error: jsonError } envelope; genuinely-unexpected errors
fall back to the configured errorStatusCode, still as JSON.

packages/api-express-router/src/endpointAdapter/apiExpressDefaultEndpointAdapter.ts
@goastler goastler marked this pull request as ready for review June 23, 2026 08:02
@goastler goastler requested a review from forgetso as a code owner June 23, 2026 08:03
Copilot AI review requested due to automatic review settings June 23, 2026 08:03
@goastler goastler requested a review from HughParry as a code owner June 23, 2026 08:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the default Express endpoint adapter’s error handling so API errors preserve their intended HTTP status codes and return the standard { error: ... } JSON envelope instead of a hardcoded 500 with a plain-text body. This aligns the adapter’s behavior with the rest of the API router error formatting and allows consumers (e.g., admin router) to receive the configured errorStatusCode for unexpected failures.

Changes:

  • Use unwrapError to serialize ProsopoBaseError-derived errors into { error: jsonError } with the error’s status code.
  • For non-Prosopo errors, respond with this.errorStatusCode and a JSON error envelope (API.UNKNOWN) instead of 500 + plain text.

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

Copilot AI review requested due to automatic review settings June 23, 2026 08:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

@goastler goastler enabled auto-merge June 24, 2026 14:06
@goastler goastler disabled auto-merge June 24, 2026 14:07
…error envelope

- Only surface an error's own HTTP status when it actually carries one
  (ProsopoApiError, or a base error with context.code); base errors
  without a status code no longer leak as 400 and now map to the
  configured errorStatusCode.
- Build the fallback envelope via a silent ProsopoApiError("API.UNKNOWN")
  run through unwrapError so the message/key stay consistent and
  localised instead of a hardcoded string.
- Add unit tests for the handleRequest error paths.
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