mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-18 22:33:44 +02:00
Fix error handling and simplify showing http errors
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { Action, action } from 'easy-peasy';
|
||||
import { FlashMessageType } from '@/components/MessageBox';
|
||||
import { httpErrorToHuman } from '@/api/http';
|
||||
|
||||
export interface FlashStore {
|
||||
items: FlashMessage[];
|
||||
addFlash: Action<FlashStore, FlashMessage>;
|
||||
addError: Action<FlashStore, { message: string; key?: string }>;
|
||||
clearAndAddError: Action<FlashStore, { message: string, key: string }>;
|
||||
clearAndAddHttpError: Action<FlashStore, { error: any, key: string }>;
|
||||
clearFlashes: Action<FlashStore, string | void>;
|
||||
}
|
||||
|
||||
@@ -28,8 +29,8 @@ const flashes: FlashStore = {
|
||||
state.items.push({ type: 'error', title: 'Error', ...payload });
|
||||
}),
|
||||
|
||||
clearAndAddError: action((state, payload) => {
|
||||
state.items = [ { type: 'error', title: 'Error', ...payload } ];
|
||||
clearAndAddHttpError: action((state, { key, error }) => {
|
||||
state.items = [ { type: 'error', title: 'Error', key, message: httpErrorToHuman(error) } ];
|
||||
}),
|
||||
|
||||
clearFlashes: action((state, payload) => {
|
||||
|
||||
Reference in New Issue
Block a user