Skip to content

Commit 9476a97

Browse files
committed
Fix InvalidTypeError message
1 parent 1b95ebf commit 9476a97

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/converters/schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function validateType(type) {
6767
var validTypes = ['integer', 'number', 'string', 'boolean', 'object', 'array'];
6868

6969
if (validTypes.indexOf(type) < 0 && type !== undefined) {
70-
throw new InvalidTypeError('Type "' + type + '" is not a valid type');
70+
throw new InvalidTypeError('Type ' + JSON.stringify(type) + ' is not a valid type');
7171
}
7272
}
7373

lib/errors/invalid-type-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ function InvalidTypeError(message) {
55
this.message = message;
66
}
77

8-
InvalidTypeError.prototype = new Error();
8+
InvalidTypeError.prototype = Error.prototype;
99

test/invalid_types.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var test = require('tape')
66
test('invalid types', function(assert) {
77
var schema, msg;
88

9-
assert.plan(3);
9+
assert.plan(4);
1010

1111
schema = {
1212
type: 'dateTime'
@@ -22,6 +22,12 @@ test('invalid types', function(assert) {
2222
msg = 'foo is invalid type';
2323
assert.throws(function() { convert(schema); }, /InvalidTypeError/, msg);
2424

25+
schema = {
26+
type: ['string', null]
27+
};
28+
29+
assert.throws(function() { convert(schema); }, /InvalidTypeError.*["string",null]/, msg);
30+
2531
schema = getSchema('schema-2-invalid-type.json');
2632

2733
msg = 'invalid type inside complex schema';

0 commit comments

Comments
 (0)