Comments (2)
Hi @alexjoverm, thanks for the idea.
This library focus on provide flat options to build more complex stuff.
Now, if you want to handle exceptions in decorated method you can place onException
advice to be invoked before main method and you should prevent main method execution using this.stop
. You want prevent main method to be invoked because you don't want execute twice.
// advice will wrap the method to be executed on try, catch block
@beforeMethod(Whatever.OnException)
myMethod(){ // <- it will not be executed it self
...
}
So, as you suggested, the method is wrapped with try, catch
.
this.stop()
try {
meta.result = meta.rawMethod.apply(meta.scope, meta.args)
} catch (err) {
// stuff
}
I'll try to give a standard solution. Anyway this is an example to handle exceptions on decorated method:
https://github.com/k1r0s/kaop-ts/blob/master/test/demos/onExceptionAdvice.spec.ts
from kaop-ts.
This is what implementation would look like
This feature should pass this test:
import { AdvicePool, IMetadata, onException, adviceMetadata } from "../../src/kaop-ts"
class MyAdvicePool extends AdvicePool {
static handleError (@adviceMetadata meta: IMetadata) {
console.log(`There was an error in ${meta.propertyKey}(): -> ${meta.err.message}`)
}
}
class ExceptionTest {
@onException(MyAdvicePool.handleError)
// static wrongMethod (callback: number | Function) {
static wrongMethod (callback: any) {
callback()
}
}
describe("kaop-ts demo -> exception join point", () => {
it("advice should be executed when decorated method throws an exception", (done) => {
ExceptionTest.wrongMethod(2)
ExceptionTest.wrongMethod(done)
})
})
Check the difference between this one and previous test
from kaop-ts.
Related Issues (20)
- reexport inject and provider from kaop pkg
- allow access to `...advices` throught function prop
- advice order is wrong when on stacked joinpoints [breaking changes]
- promise based decorators? HOT 6
- [docs] Chinese | Russian translation
- An in-range update of ts-jest is breaking the build 🚨 HOT 3
- An in-range update of @types/node is breaking the build 🚨 HOT 4
- The automated release is failing 🚨
- after constructor advices no longer stack HOT 1
- Function calls are not supported in decorators - Angular 7 HOT 3
- Version 4.0.0 silently changes target to es6 HOT 2
- utility to clear all decorators HOT 1
- An in-range update of rollup is breaking the build 🚨 HOT 48
- Result of advise's first execution repeating itself in following executions when running all tests HOT 4
- applyAspect not fully reading proto chain HOT 1
- Prevents + Commit HOT 3
- declaration for module 'kaop' is needed HOT 6
- Advices on functions defined as properties HOT 2
- Async advices HOT 1
- How do I apply advices to all the methods in every class/component in angular? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaop-ts.