MCPcopy Create free account
hub / github.com/MetaMask/rpc-errors / serializeError

Function serializeError

src/utils.ts:106–127  ·  view source on GitHub ↗
(
  error: unknown,
  {
    fallbackError = FALLBACK_ERROR,
    shouldIncludeStack = true,
    shouldPreserveMessage = true,
  } = {},
)

Source from the content-addressed store, hash-verified

104 * @returns The serialized error.
105 */
106export 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`

Callers 1

utils.test.tsFile · 0.90

Calls 1

buildErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…