File tree Expand file tree Collapse file tree
src/server/plugins/engine/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1029,6 +1029,27 @@ describe('FileUploadField', () => {
10291029 )
10301030 } )
10311031
1032+ it ( 'should throw InvalidComponentStateError when persistFiles throws 404 Not Found' , async ( ) => {
1033+ const notFoundError = Boom . notFound ( 'File not found' )
1034+ mockPersistFiles . mockRejectedValue ( notFoundError )
1035+
1036+ await expect (
1037+ fileUploadField . onSubmit ( mockRequest , mockMetadata , mockContext )
1038+ ) . rejects . toThrow ( InvalidComponentStateError )
1039+
1040+ const error = await fileUploadField
1041+ . onSubmit ( mockRequest , mockMetadata , mockContext )
1042+ . catch ( ( e : unknown ) => e )
1043+
1044+ expect ( error ) . toBeInstanceOf ( InvalidComponentStateError )
1045+ expect ( ( error as InvalidComponentStateError ) . component ) . toBe (
1046+ fileUploadField
1047+ )
1048+ expect ( ( error as InvalidComponentStateError ) . userMessage ) . toBe (
1049+ 'There was a problem with your uploaded files. Re-upload them before submitting the form again.'
1050+ )
1051+ } )
1052+
10321053 it ( 'should re-throw other Boom errors without wrapping' , async ( ) => {
10331054 const serverError = Boom . internal ( 'Internal server error' )
10341055 mockPersistFiles . mockRejectedValue ( serverError )
Original file line number Diff line number Diff line change @@ -339,6 +339,7 @@ export class FileUploadField extends FormComponent {
339339 if (
340340 Boom . isBoom ( error ) &&
341341 ( error . output . statusCode === 403 || // Forbidden - retrieval key invalid
342+ error . output . statusCode === 404 || // Not Found - file not found
342343 error . output . statusCode === 410 ) // Gone - file expired (took to long to submit, etc)
343344 ) {
344345 // Failed to persist files. We can't recover from this, the only real way we can recover the submissions is
You can’t perform that action at this time.
0 commit comments