DecoratorHandler is deprecated. How to make Interceptor without it? #4097
-
Hello there! I've been exploring interceptors in version 7.4 and noticed that While reviewing the source code of the import { type Dispatcher } from 'undici';
const clearHeadersInterceptor: Dispatcher.DispatcherComposeInterceptor =
(dispatch) => (opts, handler) => {
const initialOnResponseStart = handler.onResponseStart!.bind(handler);
const newOnResponseStart: Dispatcher.DispatchHandler['onResponseStart'] = (
controller,
statusCode,
headers,
statusMessage,
) => {
initialOnResponseStart(controller, statusCode, {}, statusMessage);
};
const proxiedHandler = new Proxy(handler, {
get: (target, key) => {
const methodOrProp =
typeof target[key] === 'function' ? target[key].bind(target) : target[key];
return key === 'onResponseStart' ? newOnResponseStart : methodOrProp;
},
});
return dispatch(opts, proxiedHandler);
}; Could you please guide me on whether this approach is acceptable, or if there will be another helper utility introduced to replace |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The I'd suggest you to take care of the usage of Check this example of an It uses |
Beta Was this translation helpful? Give feedback.
Just to confirm,
DecoratorHandler
has not been dropped, but enhanced with further APIs that sync with our new Handler's shape.So you should be able to use it for your interceptor right away