customErrors.js 1.7 KB

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