Skip to content

Instantly share code, notes, and snippets.

@itshaadi
Created January 7, 2021 20:49
Show Gist options
  • Save itshaadi/bdff24da523f118a19eb2a86165d8940 to your computer and use it in GitHub Desktop.
Save itshaadi/bdff24da523f118a19eb2a86165d8940 to your computer and use it in GitHub Desktop.
Definition of an execution unit that can fail
class CanFail implements ExecutionUnit {
next: ExecutionUnit | null;
pipeline: IAPPipeline;
constructor(pipeline: IAPPipeline) {
this.next = null;
this.pipeline = pipeline;
}
setNext(next: ExecutionUnit): void {
this.next = next;
}
async exec(req: Request, res: Response): Promise<void | never> {
try {
await this.pipeline(req, res);
} catch (e) {
console.error(e);
if (this.next !== null) {
await this.next.exec(req, res);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment