getComments
- асинхронная функция.Когда он возвращает ошибку, я хочу обработать ее через catchError
.Но я всегда выполняю map()
и никогда не выполняю catchError
.
Почему и как это исправить?
from(getComments(action.payload.url)).pipe(
map((comments: IComments[]) => commentsActions.fetch.done({ params: action.payload.url, result: { comments } })),
// TODO: 以下ではError handlingができない
catchError(error => of(commentsActions.fetch.failed({ params: action.payload.url, error: { hasError: true } }))),
),
и
export const getComments = async (url: string) => {
return await fetch(url)
.then(response => response.json())
.then(comments => comments)
.catch((e: string) => throwError(e));
}
Заранее спасибо.