5 ms·
What if there were two reasons to forbid the request?
by shabbyrobe 12y ago
What if there were two reasons to forbid the request?
- geofft 12y agomultipart/alternative? :)
- jeppebemad 12y agoReturn the error for the problem that occurs first, or - in the case of dependent errors - concatenate the problems in one error. Would be my suggestion.
- awinder 12y agoMaybe this needs to be wrapped in a "application/problem-collection+json" specification ;-)
- deathanatos 12y ago> What if there were two reasons to forbid the request? Just return the first. Most languages only have support for one error at a time (think exceptions in Python/C++/Java/C#/…, return codes in C) so returning more than one error ends up being really difficult to an API: what do you do? Raise some sort of MultipleErrors exception? (then how do you catch this?); take the first? (what was the point of multiple, then?) The same complexity exists on the server-side: you have to maintain some sort of "errors thus far" state, instead of just doing what is probably the language-natural thing: raise an exception that'll get translated to JSON. The only real case I've found for multiple errors is form-field validation, when multiple fields don't validate. I've found it's sufficient to just bottle them into a "ValidationError" and return that: it can contain a list of fields and their issues. The rest of the API can then continue to benefit from a simpler interface.