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

weird response #44

Open
CodersBrothers opened this issue Jun 12, 2016 · 5 comments
Open

weird response #44

CodersBrothers opened this issue Jun 12, 2016 · 5 comments

Comments

@CodersBrothers
Copy link
Contributor

CodersBrothers commented Jun 12, 2016

If you are using Restify, the normal error have this schema example:

{
  "code": "ResourceNotFound",
  "message": "/v1/test does not exist"
}

Have code and message.

But in restify-validator you can get something like this:

{
  "status": "validation failed",
  "errors": [
    {
      "field": "amount",
      "code": "INVALID",
      "message": "Invalid number"
    }
  ]
}

As you can see, no there are any first level code param, and there are a status param. That is the first time that I see.

Maybe will be maintain the same schema:

{
  "code": "BadRequest",
  "message": "Validation failed",
  "errors": [
    {
      "field": "amount",
      "code": "INVALID",
      "message": "Invalid number"
    }
  ]
}

The main idea is maintain a similar schema of Restify

@gchauvet
Copy link
Collaborator

Good idea, I take a look tomorrow

@CodersBrothers
Copy link
Contributor Author

If you like I can do a pull request.

I like the first part of my previous response, but the part of errors (with other code param), do you like this part? do you think in other solution better?

@gchauvet
Copy link
Collaborator

Yes, you can provide a pull request : I'm a little bit overloaded these days

@CodersBrothers
Copy link
Contributor Author

CodersBrothers commented Jun 26, 2016

I was checking yesterday the library. In my project I was working with the version 0.1.0, but now is in 1.0.5. This was the main problem, my main problem. In this version, the node-restify-validation library, implements fine the restify error handler, and I can get similar errors like restify.

Now, Restify with restify-validation 1.0.5 error response is cool:

{
  "code": "InvalidArgument",
  "message": "firstname (MISSING): Field is required"
}

Anyway, I think that will be better something like:

{
  "code": "InvalidArgument",
  "message": "Validation failed",
  "errors": [
    {
      "field": "amount",
      "type": "INVALID",
      "reason": "Invalid number"
    }
  ]
}

What do you think? @gchauvet

@gchauvet
Copy link
Collaborator

It would be interessting to normalize node-restify-validation like restify. I working on this today.

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

2 participants