aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/utilities/rxjs.ts
blob: 1be491640da0b1b07bbc87c0f9d260d21fd1a8d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { OperatorFunction } from 'rxjs';
import { catchError } from 'rxjs/operators';

export function convertError<T, NewError>(
  oldErrorType: { new (...args: never[]): unknown },
  newErrorType: { new (): NewError }
): OperatorFunction<T, T> {
  return catchError((error) => {
    if (error instanceof oldErrorType) {
      throw new newErrorType();
    }
    throw error;
  });
}