{"version":3,"file":"error-wrappers.mjs","sourceRoot":"","sources":["../../src/internals/error-wrappers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,sBAAkB;AAItC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,EAAwB;IACtD,OAAO,MAAM,gBAAiB,SAAQ,SAAS;QA0B7C;;;;;WAKG;QACH,YACE,OAAuC,EACvC,IAA2B;YAE3B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAChC,MAAM,KAAK,GAAG,EAAE,EAAE,CAAC;gBACnB,KAAK,CAAC;oBACJ,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,IAAI,EAAE,OAAO;iBACd,CAAC,CAAC;gBAEH,OAAO;YACT,CAAC;YAED,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;YAC1B,KAAK,CAAC;gBACJ,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,IAAI;aACL,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\n\nimport { SnapError } from '../errors';\n\nexport type JsonRpcErrorFunction = typeof rpcErrors.parse;\n\n/**\n * Create a `SnapError` class from an error function from\n * `@metamask/rpc-errors`. This is useful for creating custom error classes\n * which can be thrown by a Snap.\n *\n * The created class will inherit the message, code, and data properties from\n * the error function.\n *\n * @param fn - The error function to create the class from.\n * @returns The created `SnapError` class.\n */\nexport function createSnapError(fn: JsonRpcErrorFunction) {\n  return class SnapJsonRpcError extends SnapError {\n    /**\n     * Create a new `SnapJsonRpcError` from a message.\n     *\n     * @param message - The message to create the error from.\n     */\n    constructor(message?: string);\n\n    /**\n     * Create a new `SnapJsonRpcError` from data.\n     *\n     * @param data - The data to create the error from.\n     */\n    constructor(data?: Record<string, Json>);\n\n    /**\n     * Create a new `SnapJsonRpcError` from a message and data.\n     *\n     * @param message - The message to create the error from.\n     * @param data - The data to create the error from.\n     */\n    constructor(\n      message?: string | Record<string, Json>,\n      data?: Record<string, Json>,\n    );\n\n    /**\n     * Create a new `SnapJsonRpcError` from a message and data.\n     *\n     * @param message - The message to create the error from.\n     * @param data - The data to create the error from.\n     */\n    constructor(\n      message?: string | Record<string, Json>,\n      data?: Record<string, Json>,\n    ) {\n      if (typeof message === 'object') {\n        const error = fn();\n        super({\n          code: error.code,\n          message: error.message,\n          data: message,\n        });\n\n        return;\n      }\n\n      const error = fn(message);\n      super({\n        code: error.code,\n        message: error.message,\n        data,\n      });\n    }\n  };\n}\n"]}