mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
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:
commit
b9735ecc7d
@ -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;
|
||||
}
|
||||
|
||||
@ -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 = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user