Merge pull request #11541 from strapi/v4/error-handling

[v4] Add possibility to set a status on a thrown Error
This commit is contained in:
Alexandre BODIN 2021-11-10 14:22:03 +01:00 committed by GitHub
commit b9735ecc7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -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;
}

View File

@ -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 = {