mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-23 14:03:43 +00:00
feat: 统一服务端返回参数
This commit is contained in:
22
service/src/utils/index.ts
Normal file
22
service/src/utils/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
interface SendResponseOptions {
|
||||
type: 'success' | 'fail'
|
||||
message?: string
|
||||
data?: any
|
||||
}
|
||||
|
||||
export function sendResponse(options: SendResponseOptions) {
|
||||
if (options.type === 'success') {
|
||||
return Promise.resolve({
|
||||
message: options.message ?? 'Success',
|
||||
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,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user