Skip to content

Commit

Permalink
Fix error in null checking
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTanner committed Sep 19, 2016
1 parent 7e9d4cc commit 4d67307
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/request-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,23 @@ exports.unset = function(field){
* @api public
*/
exports.field = function(name, val) {
// check
if (null === name || undefined === val) {

// name should be either a string or an object.
if (null === name || undefined === name) {
throw new Error('.field(name, val) name can not be empty');
}
if (null === val || undefined === val) {
throw new Error('.field(name, val) val can not be empty');
}

if (isObject(name)) {
for (var key in name) {
this.field(key, name[key]);
}
return this;
}

// val should be defined now
if (null === val || undefined === val) {
throw new Error('.field(name, val) val can not be empty');
}
this._getFormData().append(name, val);
return this;
};
Expand Down

0 comments on commit 4d67307

Please sign in to comment.