Handling Different Types of Errors in API Calls

Not certain how to best ask this question, but what is the recommended way / approach to handling different types of errors?

Lets say I have an API call, and the following errors may occur: ItemNotFoundError, UnknownError, MissingPermissionError.

In case of MissingPermissionError and ItemNotFoundError, I would want to return those tags to the client, so it can properly handle giving feedback to the user. But in case of UnknownError, I want to log it to Sentry, and instead return InternalServerErrorfor the tag,.

Should I just log to sentry wherever that UnknownError might occur and yield an InternalServerError? Or let it bubble up and manually map/handle it from the highest level?

Hope this makes sense lol
Was this page helpful?