Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
ngrx - handling errors in reducer and effect

Having a play around using ngrx with the effects module. I'm dispatching an action, doing some async stuff via an effect, then I'm dispatching a new action to update the state, then redirect. Here's a cut down version of what i'm doing:

@Injectable()
export class Effects {

  @Effect()
  start$: Observable<Action> = this.actions$
    .ofType('start')
    // omitted for brevity
    .concatMap(action => [
      new finishAction(action.payload),
      go(['/'])
    ])
    .catch((err) => {
      console.log('err', err);
      return Observable.empty();
    })

  constructor(private actions$: Actions) {
  }
}

This all works fine - when i dispatch a start action, this effect kicks in, dispatches a finish action, then redirects back to the root (via the go action which is imported from @ngrx/router-store.

How do I handle something failing in finishAction ? At the moment i get an error in the console and then go runs regardless.

Ideally i'd like to intercept this failure, and dispatch another action (so i can show a modal or something, but not do the redirect)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If the finishAction's reducer fails the process the action the state should be changed to the error one.

You can subscribe to Effects.start$ in your component and select the error state. If the subscription receives the error you can react by moving to a new route.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!