diff --git a/packages/core/strapi/lib/middlewares/errors.js b/packages/core/strapi/lib/middlewares/errors.js index 209d8e55b8..27b94010ab 100644 --- a/packages/core/strapi/lib/middlewares/errors.js +++ b/packages/core/strapi/lib/middlewares/errors.js @@ -32,7 +32,7 @@ module.exports = (/* _, { strapi } */) => { strapi.log.error(error); - const { status, body } = formatInternalError(); + const { status, body } = formatInternalError(error); ctx.status = status; ctx.body = body; } diff --git a/packages/core/strapi/lib/services/errors.js b/packages/core/strapi/lib/services/errors.js index 87744ceba7..8313e96887 100644 --- a/packages/core/strapi/lib/services/errors.js +++ b/packages/core/strapi/lib/services/errors.js @@ -60,9 +60,14 @@ const formatHttpError = error => { }; }; -const formatInternalError = () => { - const error = createError(500); - return formatHttpError(error); +const formatInternalError = error => { + const httpError = createError(error); + + if (httpError.expose) { + return formatHttpError(httpError); + } + + return formatHttpError(createError(httpError.status || 500)); }; module.exports = {