jsend
jsend copied to clipboard
Using message with "fail"
I think that message
attribute could also be a part of fail
just as it is with error
.
As you describe it, FAIL is:
There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied
So in case of the former, the "problem with the data submitted" current structure makes perfect sense. However for "some pre-condition of the API call wasn't satisfied" it does not quite work, and a "message" describing the problem seems to be much more logical. Because this pre-condition may not depend on what data user submitted, but on other conditions outside of it. For example maybe this request only works on certain days of the week?
It also allows to handle both fail
and error
responses in the same way, by showing an error or warning and message
response from the server.
Hi,
Agree with that. In my implementations I used almost always to add message
with fail
cases, to give more informations on what is wrong.
Thumb up 👍
I agree I think there should be a message when the request fails. In fact, I think there should be a message for all the API response
What I usually do is adds a friendly message in the errors array. I always send errors as an array of objects in data, which has a message attribute. So the front-end engineers know the cause of failure.
{
"status": "fail",
"data": {
"errors": [
{
"message": "Request body should be json"
}
]
}
}