I'm trying to return a cached response through the interceptor, but I couldn't find a way to make an early return. When the call is cancelled in the interceptor, the callback function doesn't get run. I get neither the error nor the response. Ideally, I would like to return a cached response after the call is cancelled.
Here's the interceptor. I called the cancel method inside:
```js
const StreamInterceptor = function () {};
StreamInterceptor.prototype.intercept = function (request, invoker) {
const InterceptedStream = function (stream) {
this.stream = stream;
};
InterceptedStream.prototype.on = function (eventType, callback) {
this.stream.on(eventType, callback);
return this;
};
const stream = invoker(request);
stream.cancel();
return new InterceptedStream(stream);
};
```
Here's the client and the method call. The call is unary.
```js
const client = new ServiceClient('
http://localhost:8080', null, {
streamInterceptors: [new StreamInterceptor()],
});
client.hello(message, {}, (err, res) => {
console.log(res);
});
```