Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/server/plugins/engine/components/FileUploadField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,27 @@ describe('FileUploadField', () => {
)
})

it('should throw InvalidComponentStateError when persistFiles throws 404 Not Found', async () => {
const notFoundError = Boom.notFound('File not found')
mockPersistFiles.mockRejectedValue(notFoundError)

await expect(
fileUploadField.onSubmit(mockRequest, mockMetadata, mockContext)
).rejects.toThrow(InvalidComponentStateError)

const error = await fileUploadField
.onSubmit(mockRequest, mockMetadata, mockContext)
.catch((e: unknown) => e)

expect(error).toBeInstanceOf(InvalidComponentStateError)
expect((error as InvalidComponentStateError).component).toBe(
fileUploadField
)
expect((error as InvalidComponentStateError).userMessage).toBe(
'There was a problem with your uploaded files. Re-upload them before submitting the form again.'
)
})

it('should re-throw other Boom errors without wrapping', async () => {
const serverError = Boom.internal('Internal server error')
mockPersistFiles.mockRejectedValue(serverError)
Expand Down
1 change: 1 addition & 0 deletions src/server/plugins/engine/components/FileUploadField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export class FileUploadField extends FormComponent {
if (
Boom.isBoom(error) &&
(error.output.statusCode === 403 || // Forbidden - retrieval key invalid
error.output.statusCode === 404 || // Not Found - file not found
error.output.statusCode === 410) // Gone - file expired (took to long to submit, etc)
) {
// Failed to persist files. We can't recover from this, the only real way we can recover the submissions is
Expand Down
Loading