You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
721 B
43 lines
721 B
export interface JSendSuccess<T = any> { |
|
status: 'success'; |
|
data: T; |
|
} |
|
|
|
export interface JSendError { |
|
status: 'error'; |
|
message: string; |
|
code?: number; |
|
data?: any; |
|
} |
|
|
|
export interface JSendFail { |
|
status: 'fail'; |
|
data: any; |
|
} |
|
|
|
export type JSendResponse<T = any> = JSendSuccess<T> | JSendError | JSendFail; |
|
|
|
export class JSendResponseUtil { |
|
static success<T>(data: T): JSendSuccess<T> { |
|
return { |
|
status: 'success', |
|
data, |
|
}; |
|
} |
|
|
|
static error(message: string, code?: number, data?: any): JSendError { |
|
return { |
|
status: 'error', |
|
message, |
|
code, |
|
data, |
|
}; |
|
} |
|
|
|
static fail(data: any): JSendFail { |
|
return { |
|
status: 'fail', |
|
data, |
|
}; |
|
} |
|
} |