* Get the error as JSON-serializable object. * * @returns A plain object with all public class properties.
()
| 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 |
no test coverage detected