|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | var util = require('util'); |
| 4 | +var assert = require('assert') |
| 5 | +var RedisError = require('redis-parser').RedisError |
| 6 | +var ADD_STACKTRACE = false |
4 | 7 |
|
5 | | -function AbortError (obj) { |
6 | | - Error.captureStackTrace(this, this.constructor); |
| 8 | +function AbortError (obj, stack) { |
| 9 | + assert(obj, 'The options argument is required') |
| 10 | + assert.strictEqual(typeof obj, 'object', 'The options argument has to be of type object') |
| 11 | + |
| 12 | + RedisError.call(this, obj.message, ADD_STACKTRACE) |
7 | 13 | Object.defineProperty(this, 'message', { |
8 | 14 | value: obj.message || '', |
9 | 15 | configurable: true, |
10 | 16 | writable: true |
11 | 17 | }); |
| 18 | + if (stack || stack === undefined) { |
| 19 | + Error.captureStackTrace(this, AbortError) |
| 20 | + } |
12 | 21 | for (var keys = Object.keys(obj), key = keys.pop(); key; key = keys.pop()) { |
13 | 22 | this[key] = obj[key]; |
14 | 23 | } |
15 | 24 | } |
16 | 25 |
|
17 | 26 | function AggregateError (obj) { |
18 | | - Error.captureStackTrace(this, this.constructor); |
| 27 | + assert(obj, 'The options argument is required') |
| 28 | + assert.strictEqual(typeof obj, 'object', 'The options argument has to be of type object') |
| 29 | + |
| 30 | + AbortError.call(this, obj, ADD_STACKTRACE) |
19 | 31 | Object.defineProperty(this, 'message', { |
20 | 32 | value: obj.message || '', |
21 | 33 | configurable: true, |
22 | 34 | writable: true |
23 | 35 | }); |
| 36 | + Error.captureStackTrace(this, AggregateError); |
24 | 37 | for (var keys = Object.keys(obj), key = keys.pop(); key; key = keys.pop()) { |
25 | 38 | this[key] = obj[key]; |
26 | 39 | } |
27 | 40 | } |
28 | 41 |
|
29 | | -util.inherits(AbortError, Error); |
| 42 | +util.inherits(AbortError, RedisError); |
30 | 43 | util.inherits(AggregateError, AbortError); |
31 | 44 |
|
32 | 45 | Object.defineProperty(AbortError.prototype, 'name', { |
33 | 46 | value: 'AbortError', |
34 | | - // configurable: true, |
| 47 | + configurable: true, |
35 | 48 | writable: true |
36 | 49 | }); |
37 | 50 | Object.defineProperty(AggregateError.prototype, 'name', { |
38 | 51 | value: 'AggregateError', |
39 | | - // configurable: true, |
| 52 | + configurable: true, |
40 | 53 | writable: true |
41 | 54 | }); |
42 | 55 |
|
|
0 commit comments