-
Notifications
You must be signed in to change notification settings - Fork 0
Error message format
from @slifty:
The HMIS structure you are proposing here is very similar to the Google style guide but there are a few differences that I think we should consider adapting around.
Specifically, the "errors" and "error" fields are swapped, and the "errors" field is not an array in your version but probably should be.
If we want to keep the current HMIS style, I would recommend shifting the format to be more like this:
{ "errors": [
"code": "ACCOUNT_ALREADY_EXISTS",
"message": "An account with the specified username already exists. username: anyname@hmisdomain.com"
] }
Having errors be an object that contains only one field (error) means that you will never be able to return more than one error (making the "errors" label misleading). I suspect the current JSON structure is a translation from an originally XML based structure, which would totally appropriately have -- in JSON since lists are done in the form of arrays it is implied that each item in an array labeled "errors" is an error.
All that said, I like the Google style even more since it is apparently a proposed standard, but it also implies that there is only ever going to be a single "type" of error (grounded as HTTP status codes) with several sub-errors where appropriate (thus making error handling on the client side more direct since there is no question about what the primary error that needs to be handled is.)
What do you think of making one of these tweaks? The first option being the above "errors" with no "error" field, the second being something like what google does:
{ "error": { "code": HTTP_ERROR_GOES_HERE, "message": "File Not Found", "errors": [{ "domain": "Calendar", "reason": "ResourceNotFoundException", "message": "File Not Found }] } }