When the Database Says No: Bad ids, Duplicates and Not Found
An API answers each way a request can fail with the status that says whose problem it is, so a text that isn't an ObjectId gets 400, an id with no pet 404, a duplicate key (code 11000) 409, a document the validator refuses (code 121) 400, and a database that's down 500 with the details logged and never sent.
Updated

- Category
- MongoDB
- Level
- Journeyman
- Tags
- 400 Bad Request, 404 Not Found, 409 Conflict, 500 Internal Server Error, Duplicate Key Error, Error-Handling Middleware, mongodb, nodejs