remove unused
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
parent
ee444a746f
commit
428e116fc3
2 changed files with 1 additions and 34 deletions
|
@ -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;
|
|
|
@ -1,17 +1,13 @@
|
||||||
import { configureStore, Tuple } from '@reduxjs/toolkit';
|
import { configureStore, Tuple } from '@reduxjs/toolkit';
|
||||||
import { thunk, type ThunkDispatch } from 'redux-thunk';
|
import { thunk, type ThunkDispatch } from 'redux-thunk';
|
||||||
|
|
||||||
import errorsMiddleware from './middleware/errors';
|
|
||||||
import appReducer from './reducers';
|
import appReducer from './reducers';
|
||||||
|
|
||||||
import type { ActionType } from './actions';
|
import type { ActionType } from './actions';
|
||||||
|
|
||||||
const store = configureStore({
|
const store = configureStore({
|
||||||
reducer: appReducer,
|
reducer: appReducer,
|
||||||
middleware: () => new Tuple(
|
middleware: () => new Tuple(thunk),
|
||||||
thunk,
|
|
||||||
errorsMiddleware(),
|
|
||||||
),
|
|
||||||
devTools: true,
|
devTools: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue