5 ms·
Well from a client library point of view: * Make request * Has error status code? * Error * Make request * Has error string message? * Error Fairly similar c
by ErrantX 11y ago
Well from a client library point of view:
* Make request
* Has error status code?
* Error
* Make request
* Has error string message?
* Error
Fairly similar code-paths. If there was a very consistent implementation of REST API's and how they worked/responded this argument might have more legs; because client libraries could have a shared base libraries which handled this logic. As it is, API specific libraries have to implement error handling logic so it doesn't really matter.
- buro9 11y agoThe problem there is that error strings tend to change over time... an error match today may fail tomorrow. Additionally too many clients think that error messages are safe to be shown to end users. In reality error messages are seldom to never fit to be shown to end users, not least because they're not localised, but also because the target audience for an error message for an API is the developer, not the end user.
- bluetomcat 11y agoWhat's the problem with including an additional user-friendly, alert-friendly, localized message in the payload? That's a much better general solution than trying to figure out which nonsensical HTTP status code to return.
- buro9 11y agoHow does an API know the context surrounding a message to be presented? i.e. is the client a mobile one? Does it have limited space to display a message? Is the client actually a desktop client calling the API with specialist needs to show a system dialog with specific properties filled that is more than just a single error string? An API is an interface to interact with the web application, beyond providing the means to interact with resources it should make few to no assumptions about how clients of the API will act, their environment or constraints, their locale requirements, or anything. The client is best placed to decide how to communicate to the end user, and the best thing the API can do is provide clean and unequivocal instruction to the client that something has happened so that the client can do it's job of handling it how it feels is best.