Skip to content
Snippets Groups Projects
Commit 0767bf6f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

403 should be reported as "Access denied."

parent c0098c09
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!199Resolve "[MIN-321] form for reporting errors in minerva"
Pipeline #90481 passed
......@@ -2,6 +2,7 @@ import type { AppListenerEffectAPI, AppStartListening } from '@/redux/store';
import { Action, createListenerMiddleware, isRejected } from '@reduxjs/toolkit';
import { createErrorData } from '@/utils/error-report/errorReporting';
import { openErrorReportModal } from '@/redux/modal/modal.slice';
import { showToast } from '@/utils/showToast';
export const errorListenerMiddleware = createListenerMiddleware();
......@@ -12,12 +13,15 @@ export const errorMiddlewareListener = async (
{ getState, dispatch }: AppListenerEffectAPI,
): Promise<void> => {
if (isRejected(action) && action.type !== 'user/getSessionValid/rejected') {
// eslint-disable-next-line no-console
console.log(action);
const errorData = await createErrorData(action.error, getState());
// eslint-disable-next-line no-console
console.log(errorData);
dispatch(openErrorReportModal(errorData));
if (action.error.code === '403') {
showToast({
type: 'error',
message: 'Access denied.',
});
} else {
const errorData = await createErrorData(action.error, getState());
dispatch(openErrorReportModal(errorData));
}
}
};
......
......@@ -3,6 +3,7 @@ import { SerializedError } from '@reduxjs/toolkit';
import { ONE_THOUSAND } from '@/constants/common';
import {
GENERIC_AXIOS_ERROR_CODE,
NOT_FOUND_AXIOS_ERROR_CODE,
UNKNOWN_AXIOS_ERROR_CODE,
UNKNOWN_ERROR,
} from '@/utils/getErrorMessage/getErrorMessage.constants';
......@@ -48,7 +49,8 @@ export const createErrorData = async (
code &&
code !== UNKNOWN_ERROR &&
code !== UNKNOWN_AXIOS_ERROR_CODE &&
code !== GENERIC_AXIOS_ERROR_CODE
code !== GENERIC_AXIOS_ERROR_CODE &&
code !== NOT_FOUND_AXIOS_ERROR_CODE
) {
try {
javaStacktrace = (await axiosInstance.get<JavaStacktrace>(apiPath.getStacktrace(code))).data
......
......@@ -14,6 +14,9 @@ export const getErrorCode = (error: unknown): string => {
} else if (typeof error.response.data === 'string') {
code = JSON.parse(error.response.data)['error-id'];
}
if (code === undefined || code === null) {
code = `${error.response.status}`;
}
}
} catch (e) {
code = UNKNOWN_AXIOS_ERROR_CODE;
......
export const UNKNOWN_ERROR = 'An unknown error occurred. Please try again later.';
export const UNKNOWN_AXIOS_ERROR_CODE = 'UNKNOWN_AXIOS_ERROR';
export const NOT_FOUND_AXIOS_ERROR_CODE = '404';
export const GENERIC_AXIOS_ERROR_CODE = 'ERR_BAD_REQUEST';
export const HTTP_ERROR_MESSAGES = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment