As you know it's possible to use Interceptors in new versions of Angular 4.
In mine, I want to cancel a request in interceptor in some conditions. So is it possible? or maybe what should I ask is, Which way I should do that?
Also It will be Ok! if I found a way to rewrite some response to the request instead of canceling it.
As suggested above, there is more optimal way to handle the error with custom response
To Angular 6, you need can user the following structure to return a empty Observable:
@RVP's code will work, We can do one more thing for same.
add
return
only, it will also workInspired by @RVP answer I have found out that it's possible to cut the chain with an error in the same simple way using
Observable.throw()
This avoids fulfilling response promises with undefined values.
This is just a slight variant of RVP's answer
I used
NEVER
instead ofEMPTY
to avoid dealing with undefined values in my subscriptions (or promises).Use
NEVER
if you don't want your subscription callback to be invoked