Skip to content

refactor(errors): Finish the error toast and API error cleanup - #1878

Merged
yahyafakhroji merged 3 commits into
mainfrom
refactor/error-cleanup
Dec 1, 2026
Merged

yahyafakhroji merged 3 commits into
mainfrom
refactor/error-cleanup

Conversation

@yahyafakhroji

@yahyafakhroji yahyafakhroji commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem
showMutationErrorToast lived in the quota module, so 38 files imported their error toasts from quota, and its four imports from features/ only passed the layering rules through the known-violations list. Server code logged through console in 16 places, and /api routes answered errors in at least five body shapes, so clients read error, message or success depending on the route.

Solution
The toast moves next to toastApiError in app/components/error/, which clears those four known violations. Server logging goes through @/modules/logger with the request ID. The proxy, GraphQL, watch, permissions, usage, user and Grafana routes now throw the existing error classes, and the global handler answers with { code, message, status, requestId }; status codes and messages are unchanged, and the permission check reads message. A 5xx that opts out of Sentry is logged at warn, so Sentry sees the same events as before.

/api/website, /api/assistant-chat, Grafana's 503 status payload and the health check keep their bodies, because the UI or callers outside this repo read them.

Tested locally against staging: a duplicate secret name shows the moved toast with its details, and /api/usage and /api/permissions/check return the new body with the same request ID as the server log.

Preview

1877-permission-error 1877-usage-401 1877-usage-400 1877-mutation-toast

Closes #1877

showMutationErrorToast and showQuotaExceededToast now live in
app/components/error beside toastApiError, and their importers point
there. The move clears four modules-not-to-features entries from the
dependency-cruiser baseline, since a component may import features.
The server's console calls now go through the shared logger, so they
reach the same formatters and Sentry breadcrumbs as the rest of the
app. Calls inside request handlers carry the request ID.
@yahyafakhroji
yahyafakhroji requested a review from a team as a code owner December 1, 2026 12:03
@yahyafakhroji yahyafakhroji added the enhancement New feature or request label Dec 1, 2026
@yahyafakhroji yahyafakhroji self-assigned this Dec 1, 2026

@scotwells scotwells 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.

A caller without a session token now gets 503 from the Grafana connection test instead of 401. The route throws AuthenticationError inside the same try that catches Grafana outages, so its catch reports “Connection failed” before the global handler sees it. Please move the session check outside that try or rethrow the auth error. Cover both cases: a missing token returns 401 without contacting Grafana, and a genuine connection failure keeps the existing 503 body.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

🧪 Test Summary

Job Status
E2E Regression (0) ✅ success
E2E Regression (1) ✅ success
E2E Regression (2) ✅ success
E2E Regression (3) ✅ success
E2E Smoke ✅ success
Unit Tests ✅ success
Vitest Unit Tests ✅ success

View workflow run

Need another run? Use Re-run failed jobs: one shard costs a few minutes, the whole workflow about 26.

The api routes now throw the shared error classes, and the global
handler answers with the serialized AppError body, filling in the
request ID when the error has none. Status codes and messages stay as
they were, and the permission client reads the server's message. A 5xx
that opts out of Sentry is logged at warn, so none of these reach it.
@yahyafakhroji
yahyafakhroji force-pushed the refactor/error-cleanup branch from ae58c26 to 7602d3f Compare December 1, 2026 13:17
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

🧪 Test Summary

Job Status
E2E Regression (0) ✅ success
E2E Regression (1) ✅ success
E2E Regression (2) ✅ success
E2E Regression (3) ✅ success
E2E Smoke ✅ success
Unit Tests ✅ success
Vitest Unit Tests ✅ success

View workflow run

Need another run? Use Re-run failed jobs: one shard costs a few minutes, the whole workflow about 26.

@yahyafakhroji

Copy link
Copy Markdown
Contributor Author

@scotwells Good catch, thanks. The session check now runs before the try, so a missing token is a 401 again and never reaches Grafana, and a real connection failure still answers the same 503 body. Both cases have tests now.

@scotwells scotwells 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.

Missing credentials now return 401 before the route contacts Grafana. A connection failure still returns 503, so clients can distinguish signing in again from retrying an outage. CI passed.

@yahyafakhroji
yahyafakhroji merged commit a81734e into main Dec 1, 2026
19 checks passed
@yahyafakhroji
yahyafakhroji deleted the refactor/error-cleanup branch December 1, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move error toasts to a shared module and give /api errors one shape

2 participants