Reputation: 105
Getting error when switched HttpService from nestjs@common to nestjs/axios.
@Injectable()
export class AxiosClient implements OnModuleInit {
private interceptors: AxiosInterceptor[];
constructor(
private httpService: HttpService,
private authInterceptor: AuthInterceptor,
private httpsInterceptor: AgentInterceptor,
private classTransformationInterceptor: ClassTransformationInterceptor
) {
this.interceptors = [
this.classTransformationInterceptor,
this.authInterceptor,
this.httpsInterceptor,
this.userInterceptor,
];
}
onModuleInit(): void {
const interceptorManager = this.httpService.axiosRef.interceptors;
this.interceptors.forEach((interceptor) => {
interceptorManager.request.use((request) =>
interceptor**.onRequest(request)**
);
On Response and request. Argument of type 'AxiosRequestConfig' is not assignable to parameter of type 'AxiosRequestConfig'.
interceptorManager.response.use(
(response) => interceptor.onResponse(response),
// Using the Promise.reject is to keep the error passed from each interceptor and thrown out to the consumer
(error) => Promise.reject(interceptor.onResponseRejected(error))
);
});
Types of property 'method' are incompatible. Type 'string' is not assignable to type 'Method'.
Getting error in line onRequest and onResponse when passing the request response.
Its throwing the error when i am fetching the HttpService from nestjs/axios instead of nestjs/common
Upvotes: 0
Views: 719
Reputation: 105
the error got resolved with nestjs/[email protected] instead of nestjs/axios
Upvotes: 1