remove unused

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk 2024-12-12 00:13:56 +01:00
parent ee444a746f
commit 428e116fc3
2 changed files with 1 additions and 34 deletions

View file

@ -1,29 +0,0 @@
import toast from 'bigbuffet/toast';
import type { AnyAction, Middleware } from '@reduxjs/toolkit';
/** Whether the action is considered a failure. */
const isFailType = (type: string): boolean => type.endsWith('_FAIL');
/** Whether the error contains an Axios response. */
const hasResponse = (error: any): boolean => Boolean(error && error.response);
/** Don't show 401's. */
const authorized = (error: any): boolean => error?.response?.status !== 401;
/** Whether the error should be shown to the user. */
const shouldShowError = ({ type, skipAlert, error }: AnyAction): boolean =>
!skipAlert && hasResponse(error) && authorized(error) && isFailType(type);
/** Middleware to display Redux errors to the user. */
const errors = (): Middleware =>
() => next => anyAction => {
const action = anyAction as AnyAction;
if (shouldShowError(action)) {
toast.showAlertForError(action.error);
}
return next(action);
};
export default errors;

View file

@ -1,17 +1,13 @@
import { configureStore, Tuple } from '@reduxjs/toolkit';
import { thunk, type ThunkDispatch } from 'redux-thunk';
import errorsMiddleware from './middleware/errors';
import appReducer from './reducers';
import type { ActionType } from './actions';
const store = configureStore({
reducer: appReducer,
middleware: () => new Tuple(
thunk,
errorsMiddleware(),
),
middleware: () => new Tuple(thunk),
devTools: true,
});