-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(EffectsErrorHandler): Extract to separate file, rename defau…
…lt handler to describe purpose better.
- Loading branch information
1 parent
693161b
commit 25d8ad7
Showing
10 changed files
with
45 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ErrorHandler } from '@angular/core'; | ||
import { Action } from '@ngrx/store'; | ||
import { Observable } from 'rxjs'; | ||
import { catchError } from 'rxjs/operators'; | ||
|
||
export type EffectsErrorHandler = <T extends Action>( | ||
observable$: Observable<T>, | ||
errorHandler: ErrorHandler | ||
) => Observable<T>; | ||
|
||
// this is the default error handler provided in EffectsModule.forRoot | ||
export const defaultEffectsErrorHandler: EffectsErrorHandler = < | ||
T extends Action | ||
>( | ||
observable$: Observable<T>, | ||
errorHandler: ErrorHandler | ||
): Observable<T> => { | ||
return observable$.pipe( | ||
catchError(error => { | ||
if (errorHandler) errorHandler.handleError(error); | ||
// Return observable that produces this particular effect | ||
return defaultEffectsErrorHandler(observable$, errorHandler); | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters