errors.js 655 B

12345678910111213141516171819202122
  1. module.exports = class EventEmitterError extends Error {
  2. constructor (msg, code, fn = EventEmitterError, opts) {
  3. super(`${code}: ${msg}`, opts)
  4. this.code = code
  5. if (Error.captureStackTrace) {
  6. Error.captureStackTrace(this, fn)
  7. }
  8. }
  9. get name () {
  10. return 'EventEmitterError'
  11. }
  12. static OPERATION_ABORTED (cause, msg = 'Operation aborted') {
  13. return new EventEmitterError(msg, 'OPERATION_ABORTED', EventEmitterError.OPERATION_ABORTED, { cause })
  14. }
  15. static UNHANDLED_ERROR (cause, msg = 'Unhandled error') {
  16. return new EventEmitterError(msg, 'UNHANDLED_ERROR', EventEmitterError.UNHANDLED_ERROR, { cause })
  17. }
  18. }