update response interface
This commit is contained in:
parent
751c18cb32
commit
4e93523115
|
@ -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
|
||||
|
|
|
@ -21,11 +21,12 @@ export type AsyncThunkConfig = {
|
|||
export type IResponseSuccess<T = unknown> = {
|
||||
status: 'success';
|
||||
data: T;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export type IResponseError = {
|
||||
status: 'error';
|
||||
data: string;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export type IResponse<T = unknown> = IResponseSuccess<T> | IResponseError;
|
||||
|
|
|
@ -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';
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user