Answer the question
In order to leave comments, you need to log in
How to solve TypeScript error?
In the "saveExpense" method, when passing error handling "catchError(this.errorHandlerService.handleError)", this method is highlighted and the error is displayed: Argument type (error:HttpErrorResponse)=>Observable is not assignable to parameter type (err:any, caught:Observable )=> never . How to decide?
saveExpense(userid, oExpense): Observable<any> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `${this.jwtToken}`
})
};
return this.http.post(`http://localhost:5555/api/expense/${userid}`, JSON.stringify(oExpense), httpOptions).pipe(
tap(
(response: any) => console.log(response)
),
catchError(this.errorHandlerService.handleError)
);
}
export class ErrorHandlerService {
handleError(error: HttpErrorResponse) {
console.error(error);
return throwError(error.error || 'Server error');
}
}
}
Answer the question
In order to leave comments, you need to log in
catchError accepts a function like (err:any, caught:Observable)=> never
And you are trying to pass (error: HttpErrorResponse)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question