From 3a0a12acdf0504526f177bf207deb469682d20bf Mon Sep 17 00:00:00 2001 From: Ashok Suthar Date: Fri, 2 Feb 2024 09:17:00 +0100 Subject: [PATCH] [Refactor] remove custom ValueError in favor of TypeError --- lib/parse.js | 3 +-- lib/stringify.js | 3 +-- lib/value-error.js | 9 --------- test/parse.js | 2 +- test/stringify.js | 2 +- 5 files changed, 4 insertions(+), 15 deletions(-) delete mode 100644 lib/value-error.js diff --git a/lib/parse.js b/lib/parse.js index 57dd911d..7bf18968 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1,7 +1,6 @@ 'use strict'; var utils = require('./utils'); -var ValueError = require('./value-error'); var has = Object.prototype.hasOwnProperty; var isArray = Array.isArray; @@ -220,7 +219,7 @@ var normalizeParseOptions = function normalizeParseOptions(opts) { } if (opts.allowDots === false && opts.decodeDotInKeys === true) { - throw new ValueError('Provided combination is not valid: allowDots=false & decodeDotInKeys=true'); + throw new TypeError('Provided combination is not valid: allowDots=false & decodeDotInKeys=true'); } if (opts.decoder !== null && typeof opts.decoder !== 'undefined' && typeof opts.decoder !== 'function') { diff --git a/lib/stringify.js b/lib/stringify.js index 7ab744a1..52beacbd 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -3,7 +3,6 @@ var getSideChannel = require('side-channel'); var utils = require('./utils'); var formats = require('./formats'); -var ValueError = require('./value-error'); var has = Object.prototype.hasOwnProperty; var arrayPrefixGenerators = { @@ -217,7 +216,7 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) { } if (opts.allowDots === true && opts.encodeDotInKeys === false) { - throw new ValueError('Provided combination is not valid: allowDots=true & encodeDotInKeys=false'); + throw new TypeError('Provided combination is not valid: allowDots=true & encodeDotInKeys=false'); } var charset = opts.charset || defaults.charset; diff --git a/lib/value-error.js b/lib/value-error.js deleted file mode 100644 index 26f1e5ed..00000000 --- a/lib/value-error.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -var ValueError = function ValueError(message) { - var error = new Error(message); - error.name = 'ValueError'; - return error; -}; - -module.exports = ValueError; diff --git a/test/parse.js b/test/parse.js index 9d585822..a1575698 100644 --- a/test/parse.js +++ b/test/parse.js @@ -166,7 +166,7 @@ test('parse()', function (t) { { allowDots: false, decodeDotInKeys: true } ); }, { - name: 'ValueError', + name: 'TypeError', message: 'Provided combination is not valid: allowDots=false & decodeDotInKeys=true' } ); diff --git a/test/stringify.js b/test/stringify.js index e6b6cd19..538132d2 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -179,7 +179,7 @@ test('stringify()', function (t) { ); }, { message: 'Provided combination is not valid: allowDots=true & encodeDotInKeys=false', - name: 'ValueError' + name: 'TypeError' } );