How to propagate errors through catchError() properly?

后端 未结 1 1638
無奈伤痛
無奈伤痛 2021-02-07 03:24

I wrote a function that is pipe-able:

HandleHttpBasicError()
{
    return ((source:Observable) => {
        return source.pipe(         


        
相关标签:
1条回答
  • 2021-02-07 03:56

    Is it ok to chain the errors with the throw keyword ?

    Yes, it's totally fine. rxjs try-catches such cases and converts it into an error notification.

    I tryed to return Observable.throwError() but the browser say "Observable.throwError is not a function"

    With rxjs6, the Observable prototype is no longer modified to contain operators or these »creation operators«, instead they are exposed as standalone functions. You can read more about it here, but the gist of it is that you'd just return throwError(…), e.g.

    return source$.pipe(
      catchError(err => err.code === 404 
        ? throwError("Not found")
        : throwError(err)
      )
    )
    
    0 讨论(0)
提交回复
热议问题