mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
27 lines
805 B
TypeScript
27 lines
805 B
TypeScript
|
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);
|
||
|
};
|