Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions frontend/src/public/api/__tests__/isUserError.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// <reference types="jest" />
import { isUserError, USER_ERROR_STATUSES } from '../isUserError';

describe('isUserError', () => {
it.each([401, 403, 404])('status %d returns true (user error)', (status) => {
expect(isUserError(status)).toBe(true);
});

it.each([400, 500, 502, 503])('status %d returns false (app/server error)', (status) => {
expect(isUserError(status)).toBe(false);
});

it('USER_ERROR_STATUSES contains only 401, 403, 404', () => {
expect(USER_ERROR_STATUSES).toEqual([401, 403, 404]);
});
});
7 changes: 6 additions & 1 deletion frontend/src/public/api/commonRequest.ts
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { identifyAppPartOnClient } from '../utils/identifyAppPart/identifyAppPar
import { getCurrentToken } from '../utils/auth';
import { envBackendURL } from '../constants/enviroment';
import { isRequestCanceled } from '../utils/isRequestCanceled';
import { isUserError } from './isUserError';

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

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);
}
Comment thread
Maria-Lordwill marked this conversation as resolved.
} else if (error.request) {
logger.error('Request Error:', error.request);
} else {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/public/api/isUserError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const USER_ERROR_STATUSES = [401, 403, 404];

export function isUserError(status: number): boolean {
return USER_ERROR_STATUSES.includes(status);
}
Comment thread
cursor[bot] marked this conversation as resolved.