mirror of
https://github.com/strapi/strapi.git
synced 2025-10-27 08:02:56 +00:00
fix error handling on upload plugin
This commit is contained in:
parent
b58274aecb
commit
1b18aa971c
@ -21,7 +21,7 @@ module.exports = config => {
|
||||
}
|
||||
|
||||
try {
|
||||
return body({ patchKoa: true, ...bodyConfig })(ctx, next);
|
||||
await body({ patchKoa: true, ...bodyConfig })(ctx, next);
|
||||
} catch (e) {
|
||||
if ((e || {}).message && e.message.includes('maxFileSize exceeded')) {
|
||||
return ctx.payloadTooLarge('FileTooBig');
|
||||
|
||||
2
packages/core/upload/server/bootstrap.js
vendored
2
packages/core/upload/server/bootstrap.js
vendored
@ -22,6 +22,8 @@ module.exports = async ({ strapi }) => {
|
||||
}
|
||||
|
||||
await registerPermissionActions();
|
||||
|
||||
strapi.service('plugin::upload.errors').registerErrorMiddleware();
|
||||
};
|
||||
|
||||
const createProvider = config => {
|
||||
|
||||
@ -7,7 +7,7 @@ module.exports = () => {
|
||||
try {
|
||||
await next();
|
||||
} catch (e) {
|
||||
if (e instanceof FileTooLargeError) return ctx.PayloadTooLarge();
|
||||
if (e instanceof FileTooLargeError) return ctx.payloadTooLarge();
|
||||
if (e instanceof FileNotFoundError) return ctx.notFound();
|
||||
throw e;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
'handle-errors': require('./handle-errors'),
|
||||
handleErrors: require('./errors'),
|
||||
};
|
||||
|
||||
10
packages/core/upload/server/services/errors.js
Normal file
10
packages/core/upload/server/services/errors.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const initErrorMiddleware = require('../middlewares/errors');
|
||||
|
||||
module.exports = ({ strapi }) => ({
|
||||
registerErrorMiddleware() {
|
||||
const errorMiddleware = initErrorMiddleware({ strapi });
|
||||
strapi.server.router.use('/upload', errorMiddleware);
|
||||
},
|
||||
});
|
||||
@ -1,9 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const errorService = require('./errors');
|
||||
const uploadService = require('./upload');
|
||||
const imageManipulation = require('./image-manipulation');
|
||||
|
||||
module.exports = {
|
||||
errors: errorService,
|
||||
upload: uploadService,
|
||||
'image-manipulation': imageManipulation,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user