|
|
|
|
|
by b-pagis
1557 days ago
|
|
Such simple approach is limited only to errors without arguments. For more complex use cases, where we would want an error message to indicate that field value was too long and in addition provide maximum field length, we would need to introduce new field in the error response. While it is solvable by adding this information to client application side. It would create a situation where the logic is duplicated in two places (backend and client application)... Also if we would want better UX, then we would need to display all errors at the same time in the form that is incorrectly filled. This would require changing error structure to return array of errors and it potentially create a breaking change in the API or would result in confusing structure that supports both, legacy and new format... Some years ago, I wrote an article sharing the ideas on how REST API error structuring could be done depending on the complexity of application or service:
https://link.medium.com/ObW78jhDkob |
|
Most validation I’ve seen looks like:
This pattern turns into one exception per response, and some foresight in architecting exceptions would be needed