mirror of
https://github.com/strapi/strapi.git
synced 2025-10-30 01:17:28 +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
|
||||
service.decorate(oldService => {
|
||||
const newService = _.mapValues(oldService, (method, methodName) => async (...args) => {
|
||||
try {
|
||||
return await oldService[methodName].call(newService, ...args);
|
||||
} catch (error) {
|
||||
if (databaseErrorsToTransform.some(errorToTransform => error instanceof errorToTransform)) {
|
||||
throw new ValidationError(error.message);
|
||||
const newService = _.mapValues(
|
||||
oldService,
|
||||
(method, methodName) =>
|
||||
async function(...args) {
|
||||
try {
|
||||
return await oldService[methodName].call(this, ...args);
|
||||
} catch (error) {
|
||||
if (
|
||||
databaseErrorsToTransform.some(errorToTransform => error instanceof errorToTransform)
|
||||
) {
|
||||
throw new ValidationError(error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
return newService;
|
||||
});
|
||||
|
||||
@ -50,7 +50,7 @@ class ForbiddenError extends ApplicationError {
|
||||
constructor(message, details) {
|
||||
super(message, details);
|
||||
this.name = 'ForbiddenError';
|
||||
this.message = message || 'Forbidden action';
|
||||
this.message = message || 'Forbidden access';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user