mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
b519b6e1e0
* add middleware to handle 403 errors * remove log * add logic to warn the user if not all requested images could be deleted * lint * fix copy * feat(ui): simplify batchEnqueuedListener error toast logic * feat(ui): use translations for error messages * chore(ui): lint --------- Co-authored-by: Mary Hipp <maryhipp@Marys-MacBook-Air.local> Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>
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);
|
|
};
|