peerError.ts 561 B

1234567891011121314151617181920212223242526
  1. export interface PromiseEvents<OpenType, ErrorType extends string> {
  2. open: (open?: OpenType) => void;
  3. error: (error: PeerError<`${ErrorType}`>) => void;
  4. }
  5. /**
  6. * A PeerError is emitted whenever an error occurs.
  7. * It always has a `.type`, which can be used to identify the error.
  8. */
  9. export class PeerError<T extends string> extends Error {
  10. /**
  11. * @internal
  12. */
  13. constructor(type: T, err: Error | string) {
  14. if (typeof err === "string") {
  15. super(err);
  16. } else {
  17. super();
  18. Object.assign(this, err);
  19. }
  20. this.type = type;
  21. }
  22. public type: T;
  23. }