Skip to content

Commit

Permalink
feat(rx-stateful): enhance config by a custom error mapping function
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbe812 committed Jul 7, 2023
1 parent 49617e0 commit 2012f8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libs/rx-stateful/src/lib/rx-stateful$.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export function rxStateful$<T, E = unknown>(
share({
connector: () => new ReplaySubject(1),
}),
catchError((error: any) => {
error$$.next({ error: error?.message, context: 'error', hasError: true });
catchError((error: E) => {
const errorMappingFn = mergedConfig.errorMappingFn ?? ((error: E ) => (error as any)?.message);
error$$.next({ error: errorMappingFn(error), context: 'error', hasError: true });
return NEVER;
})
);
Expand Down
5 changes: 5 additions & 0 deletions libs/rx-stateful/src/lib/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ export interface RxStatefulConfig<T, E> {
* @default false
*/
keepErrorOnRefresh?: boolean;
/**
* Mapping function to map the error to a specific value.
* @param error
*/
errorMappingFn?: (error: E) => any;
}

0 comments on commit 2012f8e

Please sign in to comment.