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

Function getMessageFromCode

src/utils.ts:62–78  ·  view source on GitHub ↗
(
  code: unknown,
  fallbackMessage: string = FALLBACK_MESSAGE,
)

Source from the content-addressed store, hash-verified

60 * has no corresponding message.
61 */
62export function getMessageFromCode(
63 code: unknown,
64 fallbackMessage: string = FALLBACK_MESSAGE,
65): string {
66 if (isValidCode(code)) {
67 const codeString = code.toString();
68
69 if (hasProperty(errorValues, codeString)) {
70 return errorValues[codeString as ErrorValueKey].message;
71 }
72
73 if (isJsonRpcServerError(code)) {
74 return JSON_RPC_SERVER_ERROR_MESSAGE;
75 }
76 }
77 return fallbackMessage;
78}
79
80/**
81 * Returns whether the given code is valid.

Callers 5

utils.test.tsFile · 0.90
getJsonRpcErrorFunction · 0.90
getEthProviderErrorFunction · 0.90
errors.test.tsFile · 0.90
utils.tsFile · 0.85

Calls 3

isValidCodeFunction · 0.85
isJsonRpcServerErrorFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…