I have the following code:
this.somePromiseFn<T> // this fn is actually a promise
.then(res => res as T)
.catch(err => this.handleError<T>(err));
handleError<T>(err: HttpErrorResponse) {
// do something here
// and return like
return {} as T;
}
The above code works fine. But how I can pass the err
argument directly to the handleError
method without using another callback function. As catch
by default passes the err
to the callback function, it should also pass the err
to the handleCatchError
. I want something like:
this.somePromiseFn<T>
.then(res => res as T)
.catch(this.handleCatchError<T>); // this line gives error 'An argument for 'err' was not provided'
But the above code produces the error saying:
Expected 1 argument, but got 0.
An argument for 'err' was not provided.
Though I have visited the following question already:
But the above questions also suggest using another callback function.