Closed ethanresnick closed 6 years ago
This should also include, perhaps, outputting a nice error for error codes that come from mongo itself (like unique constraint violations) rather than from mongoose.
One detail here: catching mongo errors here and converting them to APIErrors is easy (it's just another if
/else if
statement).
The issue is that creating an APIError with the exact message that the user will ultimately want to send back to the client is probably not possible. E.g., for unique constraint errors, we can detect these (if (err.name === 'MongoError' && err.code === 11000)
) and replace them with an APIError with a message like "This resource contained some data that conflicted with another resource of the same type."
But we can't generate a message like "An account with this email address already exists"
. So, if the user wants to customize the message further in their query.catch, they need to be able to identify which APIError was created from the mongo error. That goes back to giving the APIError's codes (per #151), but I'd really like to use URLs rather than codes, which means first getting https://github.com/json-api/json-api/pull/1199 merged in.
https://github.com/ethanresnick/json-api/issues/41#issuecomment-139932830
This should also include, perhaps, outputting a nice error for error codes that come from mongo itself (like unique constraint violations) rather than from mongoose.