mirror of
https://github.com/strapi/strapi.git
synced 2025-07-17 14:02:21 +00:00

* handle fileTooBig errors Signed-off-by: Pierre Noël <petersg83@gmail.com> * add entityTooLarge error in provider plugins Signed-off-by: Pierre Noël <petersg83@gmail.com> * fix linter Signed-off-by: Pierre Noël <petersg83@gmail.com> * refacto Signed-off-by: Pierre Noël <petersg83@gmail.com> * Add better error message for 413 errors in ML Signed-off-by: soupette <cyril.lpz@gmail.com> * refacto Signed-off-by: Pierre Noël <petersg83@gmail.com> * refacto Signed-off-by: Pierre Noël <petersg83@gmail.com> Co-authored-by: soupette <cyril.lpz@gmail.com>
47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
const errorTypes = {
|
|
ENTITY_TOO_LARGE: 'entityTooLarge',
|
|
UNKNOWN_ERROR: 'unknownError',
|
|
};
|
|
|
|
const entityTooLarge = message => {
|
|
const error = new Error(message || 'Entity too large');
|
|
error.type = errorTypes.ENTITY_TOO_LARGE;
|
|
return error;
|
|
};
|
|
entityTooLarge.type = errorTypes.ENTITY_TOO_LARGE;
|
|
|
|
const unknownError = message => {
|
|
const error = new Error(message || 'Unknown error');
|
|
error.type = errorTypes.UNKNOWN_ERROR;
|
|
return error;
|
|
};
|
|
unknownError.type = errorTypes.UNKNOWN_ERROR;
|
|
|
|
const is = (err, errorFactory) => {
|
|
return err.type && err.type === errorFactory.type;
|
|
};
|
|
|
|
const convertToStrapiError = err => {
|
|
if (is(err, entityTooLarge)) {
|
|
return strapi.errors.entityTooLarge('FileTooBig', {
|
|
errors: [
|
|
{
|
|
id: 'Upload.status.sizeLimit',
|
|
message: 'file is bigger than the limit size!',
|
|
},
|
|
],
|
|
});
|
|
} else {
|
|
strapi.log.error(err);
|
|
return strapi.errors.badImplementation();
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
errors: {
|
|
entityTooLarge,
|
|
unknownError,
|
|
},
|
|
convertToStrapiError,
|
|
};
|