Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using message with "fail" #9

Open
Nixellion opened this issue Jan 6, 2021 · 3 comments
Open

Using message with "fail" #9

Nixellion opened this issue Jan 6, 2021 · 3 comments

Comments

@Nixellion
Copy link

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.

@keogblem
Copy link

keogblem commented Jan 7, 2021

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 👍

@bodolawale
Copy link

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

@sajithneyo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants