diff --git a/extensions/action/src/errors.ts b/extensions/action/src/errors.ts index 75c38a7f..9c0b78df 100644 --- a/extensions/action/src/errors.ts +++ b/extensions/action/src/errors.ts @@ -1,10 +1,14 @@ +import { + getAbortMessage, +} from './utilities'; + export class ActionAbortError extends Error { public name: string; public instanceId: symbol; public reason?: unknown; - constructor(name: string, instanceId: symbol, reason: unknown = 'unknown') { - super(`Action ${name} as been cancelled. Reason: ${reason}`); + constructor(name: string, instanceId: symbol, reason?: unknown) { + super(getAbortMessage(name, reason)); this.name = name; this.instanceId = instanceId; diff --git a/extensions/action/src/index.ts b/extensions/action/src/index.ts index f56ebfce..6e81cc5a 100644 --- a/extensions/action/src/index.ts +++ b/extensions/action/src/index.ts @@ -21,6 +21,10 @@ import { ActionAbortError, } from './errors'; +import { + getAbortMessage, +} from './utilities'; + import type { Action, ActionAbortStrategies, @@ -44,7 +48,7 @@ export const ABORT_STRATEGY = { reject(new ActionAbortError(name, id, reason)); }, warn: (name, id, resolve, reject, reason) => { - console.warn(`Action ${name} has been cancelled. Reason: ${reason || 'unknown'}`); + console.warn(getAbortMessage(name, reason)); resolve(); }, } as ActionAbortStrategies; diff --git a/extensions/action/src/utilities.ts b/extensions/action/src/utilities.ts new file mode 100644 index 00000000..adcd4f19 --- /dev/null +++ b/extensions/action/src/utilities.ts @@ -0,0 +1,3 @@ +export function getAbortMessage(name: string, reason: unknown) { + return `Action ${name} has been cancelled. Reason: ${reason || 'unknown'}`; +} \ No newline at end of file