jsend icon indicating copy to clipboard operation
jsend copied to clipboard

Using message with "fail"

Open Nixellion opened this issue 3 years ago • 3 comments

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.

Nixellion avatar Jan 06 '21 13:01 Nixellion

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 👍

keogblem avatar Jan 07 '21 02:01 keogblem

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

bodolawale avatar Feb 21 '21 20:02 bodolawale

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"
            }
        ]
    }
}

sajithneyo avatar Jul 01 '21 16:07 sajithneyo