swagger-tools icon indicating copy to clipboard operation
swagger-tools copied to clipboard

suggestion: mark response validation errors

Open bitcloud opened this issue 9 years ago • 3 comments

As input errors generate a different response code and are handled differently, make it easy to distinguish them from another by adding err.responseValidation = true to the error object.

This allows to simply do something like this:

if(err.failedValidation) {
  if(err.responseValidation) {
    res.statusCode = 500;
    res.end("Internal Error");
  } else {
    res.statusCode = 400;
    res.end("Input Error");
  }
}

bitcloud avatar Sep 13 '16 13:09 bitcloud

Well, you could check for the existence of the originalResponse property but I'm not sure that's publicized. Let me think.

whitlockjc avatar Sep 13 '16 15:09 whitlockjc

this only works if the originalRespons is not undefined. been there done that :)

bitcloud avatar Sep 13 '16 16:09 bitcloud

Any updates here? :)

bitcloud avatar Sep 15 '20 14:09 bitcloud