mirror of
https://github.com/strapi/strapi.git
synced 2025-11-07 05:38:13 +00:00
fix error handling in entity-service
This commit is contained in:
parent
b4c9ad0440
commit
70c98f7ed9
@ -59,16 +59,22 @@ module.exports = ctx => {
|
|||||||
|
|
||||||
// wrap methods to handle Database Errors
|
// wrap methods to handle Database Errors
|
||||||
service.decorate(oldService => {
|
service.decorate(oldService => {
|
||||||
const newService = _.mapValues(oldService, (method, methodName) => async (...args) => {
|
const newService = _.mapValues(
|
||||||
|
oldService,
|
||||||
|
(method, methodName) =>
|
||||||
|
async function(...args) {
|
||||||
try {
|
try {
|
||||||
return await oldService[methodName].call(newService, ...args);
|
return await oldService[methodName].call(this, ...args);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (databaseErrorsToTransform.some(errorToTransform => error instanceof errorToTransform)) {
|
if (
|
||||||
|
databaseErrorsToTransform.some(errorToTransform => error instanceof errorToTransform)
|
||||||
|
) {
|
||||||
throw new ValidationError(error.message);
|
throw new ValidationError(error.message);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return newService;
|
return newService;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -50,7 +50,7 @@ class ForbiddenError extends ApplicationError {
|
|||||||
constructor(message, details) {
|
constructor(message, details) {
|
||||||
super(message, details);
|
super(message, details);
|
||||||
this.name = 'ForbiddenError';
|
this.name = 'ForbiddenError';
|
||||||
this.message = message || 'Forbidden action';
|
this.message = message || 'Forbidden access';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user