errors.js 671 B

1234567891011121314151617181920212223242526
  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, {
  14. cause
  15. })
  16. }
  17. static UNHANDLED_ERROR(cause, msg = 'Unhandled error') {
  18. return new EventEmitterError(msg, 'UNHANDLED_ERROR', EventEmitterError.UNHANDLED_ERROR, {
  19. cause
  20. })
  21. }
  22. }