I have a service with HttpService injected and start request with @Interval(20000). In interval function I do a request to another server with this.http.get(...) but I see no reaction, wether a request nor an exception. I see only console log "handleInterval"! What is wrong?
:
import {HttpException, HttpService, Injectable} from '@nestjs/common'
@Injectable()
export class AppService {
constructor(private readonly http: HttpService) {}
@Interval(20000)
handleInterval() {
console.log('handleInterval');
let response = this.http.get('192.168.0.162:8081/diag.fhtml', {responseType: 'arraybuffer'}).pipe(
map(res => {
console.log('received data');
return res.data;
}),
catchError(e => {
console.error(e);
throw new HttpException(e.response.data, e.response.status);
}));
}
:
:
}
Nest's HttpService
makes use of RxJS
Observables. To trigger the request, you need to add .subscribe()
or make the function async
and add .toPromise()
.