diff --git a/utils/ResponseWrapper.ts b/utils/ResponseWrapper.ts index eeca5d2..8b1a422 100644 --- a/utils/ResponseWrapper.ts +++ b/utils/ResponseWrapper.ts @@ -1,6 +1,7 @@ import http from 'http' import { NextApiResponse } from 'next' import { ResponseProps } from '@types' +import { ErrorText } from './Constants' export default function ResponseWrapper( res: NextApiResponse, { code=200, message, version = 2, data, errors }: ResponseProps @@ -9,6 +10,6 @@ export default function ResponseWrapper( 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] } : {}) }) }