diff --git a/src/index.js b/src/index.js index 6132de4..1d2763a 100644 --- a/src/index.js +++ b/src/index.js @@ -43,12 +43,16 @@ function getCode(body) { module.exports = { 'application/vnd.api+json': function jsonapiFormatter(req, res, body) { - const response = { - meta: { - id: req.id(), - ...res.meta || {}, - }, - }; + const response = {} + if (res.meta !== undefined) { + response.meta = res.meta + } else { + response.meta = { id: req.id() } + if (!isProd) { + response.meta.timers = req.timers; + response.meta.path = req.path(); + } + } if (res.links !== undefined) { response.links = { ...res.links }; @@ -58,11 +62,6 @@ module.exports = { response.included = [...res.included]; } - if (!isProd) { - response.meta.timers = req.timers; - response.meta.path = req.path(); - } - if (body instanceof Error) { // check for error message res.statusCode = getCode(body);