Skip to content

Commit f863e76

Browse files
fix(api): filter 401/403/404 as user errors in logger [Sentry #18P]
1 parent 48e0f31 commit f863e76

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// <reference types="jest" />
2+
import { isUserError, USER_ERROR_STATUSES } from '../isUserError';
3+
4+
describe('isUserError', () => {
5+
it.each([401, 403, 404])('status %d returns true (user error)', (status) => {
6+
expect(isUserError(status)).toBe(true);
7+
});
8+
9+
it.each([400, 500, 502, 503])('status %d returns false (app/server error)', (status) => {
10+
expect(isUserError(status)).toBe(false);
11+
});
12+
13+
it('USER_ERROR_STATUSES contains only 401, 403, 404', () => {
14+
expect(USER_ERROR_STATUSES).toEqual([401, 403, 404]);
15+
});
16+
});

frontend/src/public/api/commonRequest.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { identifyAppPartOnClient } from '../utils/identifyAppPart/identifyAppPar
99
import { getCurrentToken } from '../utils/auth';
1010
import { envBackendURL } from '../constants/enviroment';
1111
import { isRequestCanceled } from '../utils/isRequestCanceled';
12+
import { isUserError } from './isUserError';
1213

1314
export type TRequestType = 'public' | 'local';
1415
export type TResponseType = 'json' | 'text' | 'empty';
@@ -80,7 +81,11 @@ axiosInstance.interceptors.response.use(
8081
}
8182

8283
if (error.response) {
83-
logger.error('Response Error:', error.response.data);
84+
if (isUserError(error.response.status)) {
85+
logger.info('Response Error:', error.response.data);
86+
} else {
87+
logger.error('Response Error:', error.response.data);
88+
}
8489
} else if (error.request) {
8590
logger.error('Request Error:', error.request);
8691
} else {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const USER_ERROR_STATUSES = [401, 403, 404];
2+
3+
export function isUserError(status: number): boolean {
4+
return USER_ERROR_STATUSES.includes(status);
5+
}

0 commit comments

Comments
 (0)