How to use the @walletconnect/utils.formatRpcError function in @walletconnect/utils

To help you get started, we’ve selected a few @walletconnect/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WalletConnect / walletconnect-monorepo / packages / core / src / index.ts View on Github external
protected _formatResponse (
    response: Partial
  ): IJsonRpcResponseSuccess | IJsonRpcResponseError {
    if (typeof response.id === 'undefined') {
      throw new Error(ERROR_MISSING_ID)
    }

    if (isJsonRpcResponseError(response)) {
      const error = formatRpcError(response.error)

      const errorResponse: IJsonRpcResponseError = {
        id: response.id,
        jsonrpc: '2.0',
        ...response,
        error
      }
      return errorResponse
    } else if (isJsonRpcResponseSuccess(response)) {
      const successResponse: IJsonRpcResponseSuccess = {
        id: response.id,
        jsonrpc: '2.0',
        ...response
      }

      return successResponse