mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-30 02:13:05 +00:00
23 lines
539 B
TypeScript
23 lines
539 B
TypeScript
interface SendResponseOptions<T = any> {
|
|
type: 'Success' | 'Fail'
|
|
message?: string
|
|
data?: T
|
|
}
|
|
|
|
export function sendResponse<T>(options: SendResponseOptions<T>) {
|
|
if (options.type === 'Success') {
|
|
return Promise.resolve({
|
|
message: options.message ?? null,
|
|
data: options.data ?? null,
|
|
status: options.type,
|
|
})
|
|
}
|
|
|
|
// eslint-disable-next-line prefer-promise-reject-errors
|
|
return Promise.reject({
|
|
message: options.message ?? 'Failed',
|
|
data: options.data ?? null,
|
|
status: options.type,
|
|
})
|
|
}
|