diff --git a/server/utils.lua b/server/utils.lua index f792201..76ab5bd 100644 --- a/server/utils.lua +++ b/server/utils.lua @@ -1,12 +1,13 @@ -function Response(isSuccess, errorMessage, data) +function Response(isSuccess, message, data) if not isSuccess then return { status = "error", - data = errorMessage + message = message } end return { status = "success", - data = data + data = data, + message = message } end diff --git a/web/src/types/redux.type.ts b/web/src/types/redux.type.ts index ba5143a..ecc3d07 100644 --- a/web/src/types/redux.type.ts +++ b/web/src/types/redux.type.ts @@ -21,11 +21,12 @@ export type AsyncThunkConfig = { export type IResponseSuccess = { status: 'success'; data: T; + message?: string; }; export type IResponseError = { status: 'error'; - data: string; + message: string; }; export type IResponse = IResponseSuccess | IResponseError; diff --git a/web/src/utils/misc.ts b/web/src/utils/misc.ts index a8dc4a8..597112d 100644 --- a/web/src/utils/misc.ts +++ b/web/src/utils/misc.ts @@ -1,5 +1,6 @@ // Will return whether the current environment is in a regular browser +import { toast } from 'react-toastify'; import { IResponse, IResponseSuccess } from '../types'; // and not CEF @@ -17,6 +18,9 @@ export const GuardResponse = ( response: IResponse ): response is IResponseSuccess => { if (!response) return false; - if (response.status === 'error') throw new Error(response.data); + if (response.status === 'error') throw new Error(response.message); + if (response.message) { + toast.success(response.message); + } return response.status === 'success'; };