import { OperatorFunction } from "rxjs"; import { catchError } from "rxjs/operators"; export function convertError( oldErrorType: { new (...args: never[]): unknown }, newErrorType: { new (): NewError } ): OperatorFunction { return catchError((error) => { if (error instanceof oldErrorType) { throw new newErrorType(); } throw error; }); }