[Suggestion] - add simplified class for interceptor
See original GitHub issueHi, I think it would be great to have a simplified version of the interceptor mechanism, which will use the current implementation.
I suggest to create a base interceptor class, which will look like so:
export abstract class BaseInterceptor implements NestInterceptor {
protected onBefore(request?: any) {
}
protected onAfter(data?: any) {
}
intercept(dataOrRequest: any, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
this.onBefore(dataOrRequest);
return stream$.map((data) => {
return this.onAfter(data);
});
}
}
And here is how the LoggingInterceptor
will look:
@Interceptor()
export class LoggingInterceptor extends BaseInterceptor {
onBefore(request: any) {
console.log('Before...');
}
onAfter(data) {
console.log('After...');
return data;
}
}
The benefit of this implementation is the simplified (in my opinion) API that it brings, WDYT?
Note: it would be even better if there we different mechanism for interception when it will require an interceptor to implement the onBefore and onAfter interfaces. This way inheritance won’t be needed.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:11 (7 by maintainers)
Top Results From Across the Web
simple interceptor help - Google Groups
I was trying to create some simple interceptor code, but have ... public class ExampleInterceptor implements MethodInterceptor {.
Read more >10 Using Service Interceptors to Manipulate Requests
Custom interceptors that you develop can be designed to access and modify certain elements of the data in RequestContext. Interceptors can set the...
Read more >How to Create and Use Interceptors in Angular - Scaler
Interceptors are an excellent way to modify the HTTP request or response to make it more simple and understandable.
Read more >Spring MVC Interceptor HandlerInterceptorAdapter ...
HandlerInterceptorAdapter is abstract adapter class for the HandlerInterceptor interface, for simplified implementation of ...
Read more >Is there a way to composite Interceptors - java - Stack Overflow
You would need to write your own generic dispatcher. I would suggest you to create some form of generic dispatcher which then delegate ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@wbhob, @kamilmysliwiec can I PR?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.