[Technical Request] Enhance Error handing mechanism
Opened this issue · 0 comments
lealceldeiro commented
Contact Details
No response
What technical change you'd like to see implemented in our API?
Currently the error message sent back while creating a post with constraint violations is providing info about the DB structure and in general is not what should be informed the API caller about (refer to https://api.wcdevs.org/docs/index.html#resource-post-create-err-db). i.e.:
{
"message" : "could not execute statement; SQL [n/a]; constraint [\"PUBLIC.CONSTRAINT_INDEX_34 ON PUBLIC.post(slug NULLS FIRST) VALUES ( /* 13 */ 'lorem-ipsum-dolor-sit-amet-2081143983' )\"; SQL statement:\ninsert into \"post\" (\"body\", \"excerpt\", \"published_by\", \"published_on\", \"slug\", \"status\", \"title\", \"updated_by\", \"updated_on\", \"uuid\") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-212]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement",
"context" : "",
"dateTime" : "2022-05-23 11:22:27"
}
A better approach would be one like in https://api.wcdevs.org/docs/index.html#resource-post-create-constraints, which returns the following json content:
{
"message" : "Incorrect value '' for field 'title'. Error: size must be between 3 and 200",
"context" : "",
"dateTime" : "2022-05-23 11:22:27"
}
Code of Conduct
- I agree to follow this project's Code of Conduct