node-restify-validation icon indicating copy to clipboard operation
node-restify-validation copied to clipboard

weird response

Open CodersBrothers opened this issue 8 years ago • 5 comments

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

CodersBrothers avatar Jun 12 '16 11:06 CodersBrothers

Good idea, I take a look tomorrow

gchauvet avatar Jun 12 '16 11:06 gchauvet

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?

CodersBrothers avatar Jun 12 '16 18:06 CodersBrothers

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

gchauvet avatar Jun 15 '16 07:06 gchauvet

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

CodersBrothers avatar Jun 26 '16 09:06 CodersBrothers

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

gchauvet avatar Aug 17 '16 17:08 gchauvet