Fix 401/403/404 logged as app errors instead of user errors in production [Sentry #18P]#189
Open
Maria-Lordwill wants to merge 3 commits into
Open
Fix 401/403/404 logged as app errors instead of user errors in production [Sentry #18P]#189Maria-Lordwill wants to merge 3 commits into
Maria-Lordwill wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: File name doesn't match its exported API
- Renamed the module and its test from getResponseLogLevel to isUserError and updated imports so the filename matches the exported API.
Or push these changes by commenting:
@cursor push 0c39fa3317
Preview (0c39fa3317)
diff --git a/frontend/src/public/api/__tests__/getResponseLogLevel.test.ts b/frontend/src/public/api/__tests__/isUserError.test.ts
--- a/frontend/src/public/api/__tests__/getResponseLogLevel.test.ts
+++ b/frontend/src/public/api/__tests__/isUserError.test.ts
@@ -1,5 +1,5 @@
// <reference types="jest" />
-import { isUserError, USER_ERROR_STATUSES } from '../getResponseLogLevel';
+import { isUserError, USER_ERROR_STATUSES } from '../isUserError';
describe('isUserError', () => {
it.each([401, 403, 404])('status %d returns true (user error)', (status) => {
diff --git a/frontend/src/public/api/commonRequest.ts b/frontend/src/public/api/commonRequest.ts
--- a/frontend/src/public/api/commonRequest.ts
+++ b/frontend/src/public/api/commonRequest.ts
@@ -9,7 +9,7 @@
import { getCurrentToken } from '../utils/auth';
import { envBackendURL } from '../constants/enviroment';
import { isRequestCanceled } from '../utils/isRequestCanceled';
-import { isUserError } from './getResponseLogLevel';
+import { isUserError } from './isUserError';
export type TRequestType = 'public' | 'local';
export type TResponseType = 'json' | 'text' | 'empty';
diff --git a/frontend/src/public/api/getResponseLogLevel.ts b/frontend/src/public/api/isUserError.tsThis Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
e11a417 to
b992ecb
Compare
b992ecb to
f863e76
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
The axios response interceptor in
commonRequest.tslogs ALL HTTP errors (including 401, 403, 404) aslogger.error, which triggersSentry.captureException. This floods Sentry with expected user errors (unauthorized, forbidden, not found) that are not application bugs.Context
Note
Issues #116 (PR #5 — "Not found" mixed bag) and #18Y/#184/#181/#17Z/#17K/#17H/#17E/#17D (PR #7 — public forms auth credentials) have been moved to separate investigations, as they require additional analysis of error sources beyond log filtering.
Solution
Introduced status-code-based log level filtering in the axios response interceptor. HTTP statuses 401 (Unauthorized), 403 (Forbidden), and 404 (Not Found) are now logged as
logger.info(console only, no Sentry), while all other errors (400, 5xx) remain aslogger.error(Sentry capture).Also removed duplicate
logger.error(error)from thecommonRequestcatch block — the interceptor already logs the error, so the catch block was sending the same error to Sentry a second time.Implementation Details
New file:
isUserError.tsModified:
commonRequest.ts(response interceptor)if (error.response) { - logger.error('Response Error:', error.response.data); + if (isUserError(error.response.status)) { + logger.info('Response Error:', error.response.data); + } else { + logger.error('Response Error:', error.response.data); + } }Modified:
commonRequest.ts(catch block — removed duplicate logging)} catch (error) { if (shouldThrow) { throw error; } - logger.error(error); return undefined as unknown as T; }Testing
Positive scenarios
/workflows/99999999) → API returns 404 → verify NO new error event in SentryNegative / edge cases
logger.error('Request Error:')still firesAutomated tests
frontend/src/public/api/__tests__/isUserError.test.ts— 8 tests, all passingCloses https://pneumatic.sentry.io/issues/PNEUMATIC-FRONTEND-PROD-18P/
Note
Low Risk: Only changes client-side logging severity in the Axios response interceptor for a small set of HTTP statuses and removes a redundant catch-all
logger.error, without altering request/response behavior.Note
Low Risk
Low risk: changes only client-side error logging/annotation in the Axios interceptor and suppresses duplicate logs, without altering request/response behavior.
Overview
Reduces noise in production error reporting by treating HTTP
401/403/404as user/expected failures: the Axios response interceptor now logs these aslogger.infowhile continuing to log other response failures aslogger.error.Adds
isUserError/USER_ERROR_STATUSESto centralize the status list, tags rejected errors withloggedByInterceptorto avoid duplicate logging incommonRequest, and includes Jest coverage for the new helper.Written by Cursor Bugbot for commit 8c1106e. This will update automatically on new commits. Configure here.
Note
Fix 401/403/404 HTTP errors logged as app errors instead of user errors
isUserErrorutility in isUserError.ts that identifies 401, 403, and 404 as user errors.infolevel instead oferror, reducing noise in Sentry.loggedByInterceptor: trueto prevent duplicate logging in thecommonRequestcatch clause.Macroscope summarized 8c1106e.