Improve consistency of validation error handling

Utilises common path of existing invalidParameterError
This commit is contained in:
Lovell Fuller
2019-07-26 14:58:49 +01:00
parent 28de243c11
commit 233b015d77
11 changed files with 110 additions and 135 deletions

View File

@@ -72,7 +72,7 @@ function extractChannel (channel) {
if (is.integer(channel) && is.inRange(channel, 0, 4)) {
this.options.extractChannel = channel;
} else {
throw new Error('Cannot extract invalid channel ' + channel);
throw is.invalidParameterError('channel', 'integer or one of: red, green, blue', channel);
}
return this;
}
@@ -124,7 +124,7 @@ function bandbool (boolOp) {
if (is.string(boolOp) && is.inArray(boolOp, ['and', 'or', 'eor'])) {
this.options.bandBoolOp = boolOp;
} else {
throw new Error('Invalid bandbool operation ' + boolOp);
throw is.invalidParameterError('boolOp', 'one of: and, or, eor', boolOp);
}
return this;
}