Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
fix: remove non-serializable properties from exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
danroc committed May 23, 2024
1 parent f415476 commit 20cdecd
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ export class MethodNotSupportedError extends Error {
}

/**
* Handles a keyring JSON-RPC request.
* Inner function that dispatches JSON-RPC request to the associated Keyring
* methods.
*
* @param keyring - Keyring instance.
* @param request - Keyring JSON-RPC request.
* @returns A promise that resolves to the keyring response.
*/
export async function handleKeyringRequest(
async function dispatchRequest(
keyring: Keyring,
request: JsonRpcRequest,
): Promise<Json | void> {
Expand Down Expand Up @@ -128,3 +129,40 @@ export async function handleKeyringRequest(
}
}
}

/**
* Handles a keyring JSON-RPC request.
*
* This function is meant to be used as a handler for Keyring JSON-RPC requests
* in an Accounts Snap.
*
* Example:
*
* ```typescript
* export const onKeyringRequest: OnKeyringRequestHandler = async ({
* origin,
* request,
* }) => {
* return await handleKeyringRequest(keyring, request);
* };
* ```
*
* @param keyring - Keyring instance.
* @param request - Keyring JSON-RPC request.
* @returns A promise that resolves to the keyring response.
*/
export async function handleKeyringRequest(
keyring: Keyring,
request: JsonRpcRequest,
): Promise<Json | void> {
try {
return await dispatchRequest(keyring, request);
} catch (error) {
const message =
error instanceof Error && typeof error.message === 'string'
? error.message
: 'An unknown error occurred while handling the keyring request';

throw new Error(message);
}
}

0 comments on commit 20cdecd

Please sign in to comment.