From 417484cf7335ccfcfdb177223781bb9fd78bbb92 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 15 Sep 2022 15:14:23 +0530 Subject: [PATCH] Adding new error types and exporting them from module (#909) --- src/approval/ApprovalController.ts | 3 ++- src/approval/errors.ts | 5 +++++ src/approval/index.ts | 2 ++ src/index.ts | 2 +- src/permissions/index.ts | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/approval/errors.ts create mode 100644 src/approval/index.ts diff --git a/src/approval/ApprovalController.ts b/src/approval/ApprovalController.ts index 85442ff751..3be6d4c3b8 100644 --- a/src/approval/ApprovalController.ts +++ b/src/approval/ApprovalController.ts @@ -4,6 +4,7 @@ import { nanoid } from 'nanoid'; import { BaseController, Json } from '../BaseControllerV2'; import type { RestrictedControllerMessenger } from '../ControllerMessenger'; +import { ApprovalRequestNotFoundError } from './errors'; const controllerName = 'ApprovalController'; @@ -568,7 +569,7 @@ export class ApprovalController extends BaseController< private _deleteApprovalAndGetCallbacks(id: string): ApprovalCallbacks { const callbacks = this._approvals.get(id); if (!callbacks) { - throw new Error(`Approval request with id '${id}' not found.`); + throw new ApprovalRequestNotFoundError(id); } this._delete(id); diff --git a/src/approval/errors.ts b/src/approval/errors.ts new file mode 100644 index 0000000000..7389d351b1 --- /dev/null +++ b/src/approval/errors.ts @@ -0,0 +1,5 @@ +export class ApprovalRequestNotFoundError extends Error { + constructor(id: string) { + super(`Approval request with id '${id}' not found.`); + } +} diff --git a/src/approval/index.ts b/src/approval/index.ts new file mode 100644 index 0000000000..40addb379b --- /dev/null +++ b/src/approval/index.ts @@ -0,0 +1,2 @@ +export * from './ApprovalController'; +export * from './errors'; diff --git a/src/index.ts b/src/index.ts index 76df3f28a5..240872deaf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { formatIconUrlWithProxy } from './assets/assetsUtil'; export * from './assets/AccountTrackerController'; export * from './user/AddressBookController'; -export * from './approval/ApprovalController'; +export * from './approval'; export * from './assets/AssetsContractController'; export * from './BaseController'; export { diff --git a/src/permissions/index.ts b/src/permissions/index.ts index dced5a9ac3..c2097d2fa7 100644 --- a/src/permissions/index.ts +++ b/src/permissions/index.ts @@ -1,4 +1,5 @@ export * from './Caveat'; +export * from './errors'; export * from './Permission'; export * from './PermissionController'; export * from './utils';