Created
January 7, 2021 20:49
-
-
Save itshaadi/bdff24da523f118a19eb2a86165d8940 to your computer and use it in GitHub Desktop.
Definition of an execution unit that can fail
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
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