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.
This commit is contained in:
@@ -68,6 +68,27 @@ export const getStaticHandler = ({ cachingOptions, collection }: Args): StaticHa
|
|||||||
status: 200,
|
status: 200,
|
||||||
})
|
})
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
|
/**
|
||||||
|
* If object key does not found, the getObject function attempts a ListBucket operation.
|
||||||
|
* Because of permissions, this will throw very specific error that we can catch and handle.
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
err instanceof Error &&
|
||||||
|
err.name === 'AccessDenied' &&
|
||||||
|
err.message?.includes('s3:ListBucket') &&
|
||||||
|
'type' in err &&
|
||||||
|
err.type === 'S3ServiceException'
|
||||||
|
) {
|
||||||
|
req.payload.logger.error({
|
||||||
|
collectionSlug: collection.slug,
|
||||||
|
err,
|
||||||
|
msg: `Requested file not found in cloud storage: ${params.filename}`,
|
||||||
|
params,
|
||||||
|
requestedKey: key,
|
||||||
|
})
|
||||||
|
return new Response(null, { status: 404, statusText: 'Not Found' })
|
||||||
|
}
|
||||||
|
|
||||||
req.payload.logger.error({
|
req.payload.logger.error({
|
||||||
collectionSlug: collection.slug,
|
collectionSlug: collection.slug,
|
||||||
err,
|
err,
|
||||||
|
|||||||
Reference in New Issue
Block a user