MCPcopy Create free account
hub / github.com/Web3Auth/Auth / SerializableError

Class SerializableError

src/jrpc/serializableError.ts:3–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import stringify from "json-stable-stringify";
2
3export class SerializableError<T> extends Error {
4 public code: number;
5
6 public data: T;
7
8 constructor({ code, message, data }: { code: number; message: string; data?: T }) {
9 if (!Number.isInteger(code)) {
10 throw new Error("code must be an integer");
11 }
12 if (!message || typeof message !== "string") {
13 throw new Error("message must be string");
14 }
15
16 super(message);
17 this.code = code;
18 if (data !== undefined) {
19 this.data = data;
20 }
21 }
22
23 toString(): string {
24 return stringify({
25 code: this.code,
26 message: this.message,
27 data: this.data,
28 stack: this.stack,
29 });
30 }
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected