From 4e93523115fcf315bdd41fc9bb90a36716049258 Mon Sep 17 00:00:00 2001 From: Lorraxs Date: Wed, 28 Feb 2024 12:58:09 +0700 Subject: [PATCH] update response interface --- server/utils.lua | 7 ++++--- web/src/types/redux.type.ts | 3 ++- web/src/utils/misc.ts | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) 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'; };