(
error: unknown,
{
fallbackError = FALLBACK_ERROR,
shouldIncludeStack = true,
shouldPreserveMessage = true,
} = {},
)
| 104 | * @returns The serialized error. |
| 105 | */ |
| 106 | export function serializeError( |
| 107 | error: unknown, |
| 108 | { |
| 109 | fallbackError = FALLBACK_ERROR, |
| 110 | shouldIncludeStack = true, |
| 111 | shouldPreserveMessage = true, |
| 112 | } = {}, |
| 113 | ): SerializedJsonRpcError { |
| 114 | if (!isJsonRpcError(fallbackError)) { |
| 115 | throw new Error( |
| 116 | 'Must provide fallback error with integer number code and string message.', |
| 117 | ); |
| 118 | } |
| 119 | |
| 120 | const serialized = buildError(error, fallbackError, shouldPreserveMessage); |
| 121 | |
| 122 | if (!shouldIncludeStack) { |
| 123 | delete serialized.stack; |
| 124 | } |
| 125 | |
| 126 | return serialized; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Construct a JSON-serializable object given an error and a JSON-serializable `fallbackError` |
no test coverage detected
searching dependent graphs…