payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
29.23k stars 1.81k forks source link

Downgrade level of `NotFound` error for missing element in GET HTTP request #8061

Open eliuAtFanatics opened 3 months ago

eliuAtFanatics commented 3 months ago

Link to reproduction

No response

Describe the Bug

As discussed with @DanRibbens and @jmikrut, the error from a GET request for a missing element currently spits a message such as

ERROR (payload): NotFound: The requested resource was not found.
    at findByID (/Users/ben.routson/Repos/playmaker-cms/node_modules/.pnpm/payload@2.24.1_@types+react@18.2.55_typescript@4.9.5_webpack@5.90.1/node_modules/payload/src/collections/operations/findByID.ts:94:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at findByIDHandler (/Users/ben.routson/Repos/playmaker-cms/node_modules/.pnpm/payload@2.24.1_@types+react@18.2.55_typescript@4.9.5_webpack@5.90.1/node_modules/payload/src/collections/requestHandlers/findByID.ts:26:17)

James and I agreed that this should be downgraded to an info level message, as opposed to a system error, and can still be considered to return an HTTP 404 response. Thus, this ticket is requested to log the work to ensure that this type of GET message doesn't spit out a system error message/status.

To Reproduce

Just create a HTTP GET request for an element that doesn't exist in the DB/system, and observe the system/console for this error message.

Payload Version

2.24.1

Adapters and Plugins

No response

DanRibbens commented 3 months ago

This would be a breaking change so I think there needs to be a feature flag specific to this or possibly a way to set the level of error for other thrown errors as well. For example ValidationError is another that comes up all the time and doesn't need to pollute the logs typically.

We will discuss the API around how this will be configurable.

eliuAtFanatics commented 3 months ago

Makes sense then, I'll stay posted on this thread for any updates.