InvokeAI/invokeai/frontend/web/src/services/api/authToastMiddleware.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
805 B
TypeScript
Raw Normal View History

import { isRejectedWithValue } from '@reduxjs/toolkit';
import type { MiddlewareAPI, Middleware } from '@reduxjs/toolkit';
import { addToast } from 'features/system/store/systemSlice';
import { t } from 'i18next';
export const authToastMiddleware: Middleware =
(api: MiddlewareAPI) => (next) => (action) => {
if (isRejectedWithValue(action)) {
if (action.payload.status === 403) {
const { dispatch } = api;
const customMessage =
action.payload.data.detail !== 'Forbidden'
? action.payload.data.detail
: undefined;
dispatch(
addToast({
title: t('common.somethingWentWrong'),
status: 'error',
description: customMessage,
})
);
}
}
return next(action);
};