@univerjs/network v0.5.0-beta.1 • Docs
Type Alias: HTTPInterceptorFn()
type HTTPInterceptorFn: (request, next) => Observable<HTTPEvent<unknown>>;
HTTP interceptor function. When the interceptor is called, it would receive a request object and a next function.
Parameters
Parameter | Type | Description |
---|---|---|
request | HTTPRequest | The request could be been modified by interceptors whose priority is higher than the current interceptor. |
next | HTTPHandlerFn | When the interceptor decides to pass the request to the next interceptor, it should call the next function with the request. The next function would return an Observable . The current interceptor should subscribe to it and emit the messages from next interceptor to the previous interceptor. |
Returns
Observable
<HTTPEvent
<unknown
>>
An Observable
that emits the response of the request. It would be subscribed by the previous interceptor.
An interceptor the logs the request and response would look like this:
Example
function logInterceptor(request: HTTPRequest, next: HTTPHandlerFn): Observable<HTTPEvent<unknown>> {
console.log('Request:', request);
return next(request).pipe(cat(response => console.log('Response:', response)));
}
Defined in
submodules/univer/packages/network/src/services/http/interceptor.ts:43