MCPcopy Index your code
hub / github.com/MetaMask/rpc-errors / serialize

Method serialize

src/classes.ts:62–84  ·  view source on GitHub ↗

* Get the error as JSON-serializable object. * * @returns A plain object with all public class properties.

()

Source from the content-addressed store, hash-verified

60 * @returns A plain object with all public class properties.
61 */
62 serialize(): SerializedJsonRpcError {
63 const serialized: SerializedJsonRpcError = {
64 code: this.code,
65 message: this.message,
66 };
67
68 if (this.data !== undefined) {
69 // `this.data` is not guaranteed to be a plain object, but this simplifies
70 // the type guard below. We can safely cast it because we know it's a
71 // JSON-serializable value.
72 serialized.data = this.data as { [key: string]: Json };
73
74 if (isPlainObject(this.data)) {
75 serialized.data.cause = serializeCause(this.data.cause);
76 }
77 }
78
79 if (this.stack) {
80 serialized.stack = this.stack;
81 }
82
83 return serialized;
84 }
85
86 /**
87 * Get a string representation of the serialized error, omitting any circular

Callers 1

toStringMethod · 0.95

Calls 1

serializeCauseFunction · 0.90

Tested by

no test coverage detected