Skip to content

Commit 8e90937

Browse files
Handle 404 file not found responses from persistFiles API (#355)
1 parent cd899dd commit 8e90937

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/server/plugins/engine/components/FileUploadField.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

src/server/plugins/engine/components/FileUploadField.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)