-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add foundation of error handling logic (#51)
- Loading branch information
Showing
31 changed files
with
1,173 additions
and
545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
packages/automated-dispute/src/exceptions/chainNotAdded.exception.ts
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
packages/automated-dispute/src/exceptions/customContractError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
EboEvent, | ||
EboEventName, | ||
ErrorContext, | ||
ErrorHandlingStrategy, | ||
ErrorName, | ||
} from "../types/index.js"; | ||
|
||
export class CustomContractError extends Error { | ||
public override name: ErrorName; | ||
public strategy: ErrorHandlingStrategy; | ||
public context!: ErrorContext; | ||
private customActions: Map<ErrorName, (context: ErrorContext) => Promise<void> | void> = | ||
new Map(); | ||
|
||
constructor(name: ErrorName, strategy: ErrorHandlingStrategy) { | ||
super(`Contract reverted: ${name}`); | ||
this.name = name; | ||
this.strategy = strategy; | ||
} | ||
|
||
public setContext(context: ErrorContext): this { | ||
this.context = context; | ||
return this; | ||
} | ||
|
||
public getContext(): ErrorContext { | ||
return this.context; | ||
} | ||
|
||
/** | ||
* Sets the context specific to processEvents. | ||
* This method replaces addContext for processEvents-related context updates. | ||
* | ||
* @param event The event being processed. | ||
* @param reenqueueEvent Callback to reenqueue the event. | ||
* @param terminateActor Callback to terminate the actor. | ||
* @returns The error instance. | ||
*/ | ||
public setProcessEventsContext( | ||
event: EboEvent<EboEventName>, | ||
reenqueueEvent: () => void, | ||
terminateActor: () => void, | ||
): this { | ||
this.context = { | ||
...this.context, | ||
event, | ||
reenqueueEvent, | ||
terminateActor, | ||
}; | ||
return this; | ||
} | ||
|
||
public on(errorName: string, action: (context: ErrorContext) => Promise<void> | void): this { | ||
if (this.name === errorName) { | ||
this.customActions.set(errorName, action); | ||
} | ||
return this; | ||
} | ||
|
||
public async executeCustomAction(): Promise<void> { | ||
const action = this.customActions.get(this.name) || this.strategy.customAction; | ||
if (action) { | ||
await action(this.context); | ||
} | ||
} | ||
} |
Oops, something went wrong.