Skip to content

[Fix] Surface API errors in logs and return MCP validation failures as 400s - #988

Merged
mrubens merged 2 commits into
developfrom
fix/api-error-visibility
Aug 2, 2026
Merged

[Fix] Surface API errors in logs and return MCP validation failures as 400s#988
mrubens merged 2 commits into
developfrom
fix/api-error-visibility

Conversation

@mrubens

@mrubens mrubens commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What changed

  • apps/api/src/server.ts: the app-level onError handler now logs unexpected errors server-side (console.error with request method, path, and the error with stack) before responding, for both HTTPException >= 500 and generic errors. Sentry capture is unchanged.
  • apps/api/src/handlers/custom-automations/index.ts: the create, update, and resolve-schedule MCP routes now translate expected validation failures thrown as plain Errors (missing environment, cron/schedule validation, automation cap, target configuration, etc.) into 400 responses carrying the message. Postgres duplicate-name unique violations (code 23505 on custom_automations_name_unique_idx, including drizzle-wrapped causes) return a friendly "A custom automation with this name already exists." message. Anything not on the known-pattern allowlist is rethrown so the app-level handler logs it and returns an opaque 500.
  • Added apps/api/src/handlers/custom-automations/__tests__/custom-automations-routes.test.ts covering the 400 translations (missing environment, duplicate name direct and cause-wrapped, automation cap, schedule validation) and the rethrow-to-500 path for create, update, and resolve-schedule.

Why this change was made

  • A 500 from the API previously left zero server-side trace when Sentry was not enabled (the local-dev default), since captureApiException is a no-op in that case.
  • The admin-only custom-automations MCP surface returned a bare internal_server_error for expected validation failures, so the calling agent could not see what was wrong or self-correct. The web tRPC layer already surfaces these same messages to admins.

Impact

  • Every unexpected API 500 now appears in the server logs with request context and a stack trace.
  • Agents using manage_custom_automations get actionable 400 messages for expected failures instead of opaque 500s; truly unexpected errors still return 500 and are now logged.

@roomote-community

roomote-community Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

No new code issues found. See task

  • apps/api/src/handlers/custom-automations/index.ts:87-91 treats any PostgreSQL 23505 as this name conflict. Require custom_automations_name_unique_idx too, otherwise an unrelated unique-constraint failure is misreported as a duplicate automation and bypasses 500 logging.

Reviewed 6acd98c

@mrubens
mrubens merged commit bb54c06 into develop Aug 2, 2026
17 of 18 checks passed
@mrubens
mrubens deleted the fix/api-error-visibility branch August 2, 2026 05:50
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.

1 participant