fix(storage-s3): return error status 404 when file is not found instead of 500 (#11733)

### What?

The s3 storage adapter returns a 500 internal server error when a file
is not found.
It's expected that it will return 404 when a file is not found.

### Why?

The getObject function from aws s3 sdk does not return undefined when a
blob is not found, but throws a NoSuchKey error:
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-s3/Class/NoSuchKey/

### How?

Check if exception thrown is of type NoSuchKey and return a 404 in that
case.

Related discord discussion:

https://discord.com/channels/967097582721572934/1350826594062696539/1350826594062696539
This commit is contained in:
Anders Semb Hermansen
2025-06-11 14:04:25 +02:00
committed by GitHub
parent 860e0b4ff9
commit a19921d08f
2 changed files with 9 additions and 5 deletions

View File

@@ -110,6 +110,11 @@ describe('@payloadcms/storage-s3', () => {
expect(response.headers.get('Content-Type')).toBe('image/png')
})
it('should return 404 when the file is not found', async () => {
const response = await restClient.GET(`/${mediaSlug}/file/missing.png`)
expect(response.status).toBe(404)
})
describe('R2', () => {
it.todo('can upload')
})