1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

Use built-in error classes to make errors more specific

This commit is contained in:
Ruben Bridgewater
2016-04-25 01:35:56 +02:00
parent 5368e7477e
commit bf394923fd
3 changed files with 9 additions and 10 deletions

View File

@@ -12,7 +12,7 @@ module.exports = function createClient (port_arg, host_arg, options) {
host = host_arg;
} else {
if (options && host_arg) {
throw new Error('Unknown type of connection in createClient()');
throw new TypeError('Unknown type of connection in createClient()');
}
options = options || host_arg;
}
@@ -50,14 +50,14 @@ module.exports = function createClient (port_arg, host_arg, options) {
if (options[elem] === parsed.query[elem]) {
console.warn('node_redis: WARNING: You passed the ' + elem + ' option twice!');
} else {
throw new Error('The ' + elem + ' option is added twice and does not match');
throw new RangeError('The ' + elem + ' option is added twice and does not match');
}
}
options[elem] = parsed.query[elem];
}
}
} else if (parsed.hostname) {
throw new Error('The redis url must begin with slashes "//" or contain slashes after the redis protocol');
throw new RangeError('The redis url must begin with slashes "//" or contain slashes after the redis protocol');
} else {
options.path = port_arg;
}
@@ -67,12 +67,12 @@ module.exports = function createClient (port_arg, host_arg, options) {
options.host = options.host || host_arg;
if (port_arg && arguments.length !== 1) {
throw new Error('To many arguments passed to createClient. Please only pass the options object');
throw new TypeError('To many arguments passed to createClient. Please only pass the options object');
}
}
if (!options) {
throw new Error('Unknown type of connection in createClient()');
throw new TypeError('Unknown type of connection in createClient()');
}
return options;