-
Notifications
You must be signed in to change notification settings - Fork 3
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
Show exra information in validation error messages #108
Conversation
@@ -39,7 +40,11 @@ module.exports = function (value, name, declaration) { | |||
case 'number': | |||
var parsedValue = parseFloat(value); | |||
if (Number.isNaN(parsedValue)) { | |||
throw new ApiError(ApiError.BAD_REQUEST, 'invalid value for ' + name + ' parameter'); | |||
var errorMessage = util.format( | |||
'invalid value for "%s" parameter, expected type "%s" but got "%d"', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you using %d
if value was NaN?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you suggest using %s
?
%d -> NaN
%s -> nan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You used value
, not parsedValue
,
%s for value variable may be string or Object or undefined etc
%s for parsedValue always be NaN
ba7dc35
to
cb42d6b
Compare
lgtm except copy-paste |
@@ -39,7 +40,11 @@ module.exports = function (value, name, declaration) { | |||
case 'number': | |||
var parsedValue = parseFloat(value); | |||
if (Number.isNaN(parsedValue)) { | |||
throw new ApiError(ApiError.BAD_REQUEST, 'invalid value for ' + name + ' parameter'); | |||
var errorMessage = util.format( | |||
'invalid value for "%s" parameter, expected type "%s" but got "NaN"', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's show got type: typeof value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but please keep value as well
cb42d6b
to
a063c06
Compare
/cc @dfilatov @zloylos