Skip to content

Commit f29e633

Browse files
authored
fix(payload-cloud): improve not found logging (#10058)
In Payload Cloud, an unhelpful message would be surfaced if attempting to retrieve a non-existent file. This improves the log message and response to be more helpful.
1 parent 93dde52 commit f29e633

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/payload-cloud/src/staticHandler.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ export const getStaticHandler = ({ cachingOptions, collection }: Args): StaticHa
6868
status: 200,
6969
})
7070
} catch (err: unknown) {
71+
/**
72+
* If object key does not found, the getObject function attempts a ListBucket operation.
73+
* Because of permissions, this will throw very specific error that we can catch and handle.
74+
*/
75+
if (
76+
err instanceof Error &&
77+
err.name === 'AccessDenied' &&
78+
err.message?.includes('s3:ListBucket') &&
79+
'type' in err &&
80+
err.type === 'S3ServiceException'
81+
) {
82+
req.payload.logger.error({
83+
collectionSlug: collection.slug,
84+
err,
85+
msg: `Requested file not found in cloud storage: ${params.filename}`,
86+
params,
87+
requestedKey: key,
88+
})
89+
return new Response(null, { status: 404, statusText: 'Not Found' })
90+
}
91+
7192
req.payload.logger.error({
7293
collectionSlug: collection.slug,
7394
err,

0 commit comments

Comments
 (0)