1

I would like to handle Timeout error when effect make an Http Request.

Here's my effect

loadSchedulings$ = createEffect(() =>
  this.actions$.pipe(
    ofType(ESchedulesActions.GetSchedulesByDate),
    mergeMap(() =>
      this.apiCallsService.getSchedulings().pipe(
        map(trips => ({ type: ESchedulesActions.GetSchedulesByDateSuccess, payload: trips })),
        catchError(err => {
          console.log(err);
          return EMPTY;
        })
      )
    )
  )
);

Here's my getSchedulingService

getSchedulings() {
  return this.http.get<ISchedules>(this.urlData).pipe(
    map(data => {
      ...
      return groupByDate;
    }),
    timeout(2500),
    catchError(error => of(`Request timed out`))
  );
}

Actually no error is catched by catchError inside my effect , however I send error inside my service function.

How to do that using rxjs operators ?

1 Answer 1

1

The way I see this is that you are going to catch the error in your getSchedulings() call and you never propagate this error, instead you return a new observable of it. try replacing the of with a throwError:

    catchError(error => throwError(`Request timed out`))

which will then in turn be handled by your effect

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.