mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 01:47:13 +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 { |     try { | ||||||
|       return body({ patchKoa: true, ...bodyConfig })(ctx, next); |       await body({ patchKoa: true, ...bodyConfig })(ctx, next); | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       if ((e || {}).message && e.message.includes('maxFileSize exceeded')) { |       if ((e || {}).message && e.message.includes('maxFileSize exceeded')) { | ||||||
|         return ctx.payloadTooLarge('FileTooBig'); |         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(); |   await registerPermissionActions(); | ||||||
|  | 
 | ||||||
|  |   strapi.service('plugin::upload.errors').registerErrorMiddleware(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const createProvider = config => { | const createProvider = config => { | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ module.exports = () => { | |||||||
|     try { |     try { | ||||||
|       await next(); |       await next(); | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       if (e instanceof FileTooLargeError) return ctx.PayloadTooLarge(); |       if (e instanceof FileTooLargeError) return ctx.payloadTooLarge(); | ||||||
|       if (e instanceof FileNotFoundError) return ctx.notFound(); |       if (e instanceof FileNotFoundError) return ctx.notFound(); | ||||||
|       throw e; |       throw e; | ||||||
|     } |     } | ||||||
| @ -1,5 +1,5 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
| 
 | 
 | ||||||
| module.exports = { | 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'; | 'use strict'; | ||||||
| 
 | 
 | ||||||
|  | const errorService = require('./errors'); | ||||||
| const uploadService = require('./upload'); | const uploadService = require('./upload'); | ||||||
| const imageManipulation = require('./image-manipulation'); | const imageManipulation = require('./image-manipulation'); | ||||||
| 
 | 
 | ||||||
| module.exports = { | module.exports = { | ||||||
|  |   errors: errorService, | ||||||
|   upload: uploadService, |   upload: uploadService, | ||||||
|   'image-manipulation': imageManipulation, |   'image-manipulation': imageManipulation, | ||||||
| }; | }; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pierre Noël
						Pierre Noël