mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
chore: not sending message at no data
This commit is contained in:
parent
c6606f0e9b
commit
17b965547e
@ -1,6 +1,7 @@
|
||||
import http from 'http'
|
||||
import { NextApiResponse } from 'next'
|
||||
import { ResponseProps } from '@types'
|
||||
import { ErrorText } from './Constants'
|
||||
export default function ResponseWrapper<T=unknown>(
|
||||
res: NextApiResponse,
|
||||
{ code=200, message, version = 2, data, errors }: ResponseProps<T>
|
||||
@ -9,6 +10,6 @@ export default function ResponseWrapper<T=unknown>(
|
||||
if (!http.STATUS_CODES[code]) throw new Error('Invalid http code.')
|
||||
res.statusCode = code
|
||||
res.setHeader('Access-Control-Allow-Origin', process.env.KOREANBOTS_URL)
|
||||
res.json({ code, message: message || http.STATUS_CODES[code], data, errors, version })
|
||||
res.json({ code, data, errors, version, ...(message || !data ? { message: message || ErrorText[code] || http.STATUS_CODES[code] } : {}) })
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user