From 17b965547e9b351886522fb4fc7677382805e951 Mon Sep 17 00:00:00 2001 From: Junseo Park Date: Wed, 17 Feb 2021 15:17:14 +0900 Subject: [PATCH] chore: not sending message at no data --- utils/ResponseWrapper.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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] } : {}) }) }