How should an API return errors?
Model answer
Use a consistent JSON shape, such as { error: { code, message, details } }, with the correct HTTP status. Give useful messages for the client, but never leak stack traces, SQL or secrets. Log full details on the server with a request id.
Learn this topic
Build a REST API: Create, Read, Update and Delete Tasks in the course Node.js and Express: Build a Back End API from Scratch.
Sign in to add your own answer.