Skip to content

Commit

Permalink
revert: replace deprecated throwError usage
Browse files Browse the repository at this point in the history
This reverts commit <3a9e1da4ad78ceedbf00a2088613848e8bbce353>.

Closes ngrx#3702
  • Loading branch information
markonyango committed Dec 30, 2022
1 parent 8636734 commit 430a23f
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 50 deletions.
4 changes: 2 additions & 2 deletions modules/component-store/spec/component-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ describe('Component Store', () => {
const updater = componentStore.updater<unknown>(() => ({}));

expect(() => {
updater(throwError(() => error));
updater(throwError(error));
}).toThrow(error);
});

Expand All @@ -657,7 +657,7 @@ describe('Component Store', () => {
const error = new Error('ERROR!');

expect(() => {
componentStore.patchState(throwError(() => error));
componentStore.patchState(throwError(error));
}).toThrow(error);
});

Expand Down
6 changes: 2 additions & 4 deletions modules/component-store/spec/tap-response.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ describe('tapResponse', () => {
const errorCallback = jest.fn<void, [{ message: string }]>();
const error = { message: 'error' };

throwError(() => error)
.pipe(tapResponse(noop, errorCallback))
.subscribe();
throwError(error).pipe(tapResponse(noop, errorCallback)).subscribe();

expect(errorCallback).toHaveBeenCalledWith(error);
});
Expand Down Expand Up @@ -50,7 +48,7 @@ describe('tapResponse', () => {
new Observable((subscriber) => subscriber.next(1))
.pipe(
concatMap(() =>
throwError(() => 'error').pipe(
throwError('error').pipe(
tapResponse(noop, noop),
finalize(innerCompleteCallback)
)
Expand Down
2 changes: 1 addition & 1 deletion modules/component-store/src/component-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class ComponentStore<T extends object> implements OnDestroy {
return EMPTY;
}

return throwError(() => error);
return throwError(error);
}),
takeUntil(this.destroy$)
)
Expand Down
16 changes: 7 additions & 9 deletions modules/component/spec/core/render-event/manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('createRenderEventManager', () => {
it('should call error handler with reset and synchronous flags when error is emitted', () => {
const { renderEventManager, errorHandler } = setup<number>();

renderEventManager.nextPotentialObservable(throwError(() => 'ERROR!'));
renderEventManager.nextPotentialObservable(throwError('ERROR!'));
expect(errorHandler).toHaveBeenCalledWith({
type: 'error',
error: 'ERROR!',
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('createRenderEventManager', () => {
setup<number>();

renderEventManager.nextPotentialObservable(
timer(100).pipe(switchMap(() => throwError(() => 'ERROR!')))
timer(100).pipe(switchMap(() => throwError('ERROR!')))
);

expect(suspenseHandler).toHaveBeenCalledWith({
Expand Down Expand Up @@ -389,7 +389,7 @@ describe('createRenderEventManager', () => {
nextHandler,
errorHandler,
completeHandler,
} = withNextObservableSetup<number>(throwError(() => 'ERROR!'));
} = withNextObservableSetup<number>(throwError('ERROR!'));

renderEventManager.nextPotentialObservable(of(100));

Expand Down Expand Up @@ -514,7 +514,7 @@ describe('createRenderEventManager', () => {
completeHandler,
} = withNextObservableSetup(of(200));

renderEventManager.nextPotentialObservable(throwError(() => 'ERROR!'));
renderEventManager.nextPotentialObservable(throwError('ERROR!'));

// first observable
expect(nextHandler).toHaveBeenCalledWith({
Expand Down Expand Up @@ -544,12 +544,10 @@ describe('createRenderEventManager', () => {

it('should not call error handler second time when same error is emitted twice', () => {
const { renderEventManager, errorHandler } = withNextObservableSetup(
throwError(() => 'SAME_ERROR!')
throwError('SAME_ERROR!')
);

renderEventManager.nextPotentialObservable(
throwError(() => 'SAME_ERROR!')
);
renderEventManager.nextPotentialObservable(throwError('SAME_ERROR!'));
expect(errorHandler).toHaveBeenCalledWith({
type: 'error',
error: 'SAME_ERROR!',
Expand Down Expand Up @@ -650,7 +648,7 @@ describe('createRenderEventManager', () => {
} = withNextObservableSetup(new BehaviorSubject('ngrx/component'));

renderEventManager.nextPotentialObservable(
timer(100).pipe(switchMap(() => throwError(() => 'ERROR!')))
timer(100).pipe(switchMap(() => throwError('ERROR!')))
);

// first observable
Expand Down
8 changes: 4 additions & 4 deletions modules/component/spec/let/let.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,15 @@ describe('LetDirective', () => {
});

it('should render error when error event is emitted', () => {
letDirectiveTestComponent.value$ = throwError(() => 'error message');
letDirectiveTestComponent.value$ = throwError('error message');
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('error message');
});

it('should call error handler when error event is emitted', () => {
const errorHandler = TestBed.inject(ErrorHandler);
const error = new Error('ERROR');
letDirectiveTestComponent.value$ = throwError(() => error);
letDirectiveTestComponent.value$ = throwError(error);
fixtureLetDirectiveTestComponent.detectChanges();
expect(errorHandler.handleError).toHaveBeenCalledWith(error);
});
Expand Down Expand Up @@ -463,7 +463,7 @@ describe('LetDirective', () => {
});

it('should render main template when observable emits error event', () => {
letDirectiveTestComponent.value$ = throwError(() => 'ERROR!');
letDirectiveTestComponent.value$ = throwError('ERROR!');
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('undefined');
});
Expand Down Expand Up @@ -493,7 +493,7 @@ describe('LetDirective', () => {
letDirectiveTestComponent.value$ = new BehaviorSubject('ngrx');
fixtureLetDirectiveTestComponent.detectChanges();
letDirectiveTestComponent.value$ = timer(100).pipe(
switchMap(() => throwError(() => 'ERROR!'))
switchMap(() => throwError('ERROR!'))
);
fixtureLetDirectiveTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe('Loading...');
Expand Down
12 changes: 6 additions & 6 deletions modules/component/spec/push/push.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ describe('PushPipe', () => {
});

it('should return undefined as value when error observable is initially passed', () => {
expect(pushPipe.transform(throwError(() => 'ERROR!'))).toBe(undefined);
expect(pushPipe.transform(throwError('ERROR!'))).toBe(undefined);
});

it('should call error handler when error observable is passed', () => {
const errorHandler = TestBed.inject(ErrorHandler);
pushPipe.transform(throwError(() => 'ERROR!'));
pushPipe.transform(throwError('ERROR!'));
expect(errorHandler.handleError).toHaveBeenCalledWith('ERROR!');
});

Expand All @@ -122,7 +122,7 @@ describe('PushPipe', () => {

it('should return undefined as value when new error observable is passed', () => {
expect(pushPipe.transform(of(10))).toBe(10);
expect(pushPipe.transform(throwError(() => 'ERROR!'))).toBe(undefined);
expect(pushPipe.transform(throwError('ERROR!'))).toBe(undefined);
});

it('should return non-observable value when it was passed after observable', () => {
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('PushPipe', () => {
});

it('should render undefined when error observable is initially passed', () => {
pushPipeTestComponent.value$ = throwError(() => 'ERROR!');
pushPipeTestComponent.value$ = throwError('ERROR!');
fixturePushPipeTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe(
wrapWithSpace('undefined')
Expand All @@ -246,7 +246,7 @@ describe('PushPipe', () => {

it('should call error handler when error observable is passed', () => {
const errorHandler = TestBed.inject(ErrorHandler);
pushPipeTestComponent.value$ = throwError(() => 'ERROR!');
pushPipeTestComponent.value$ = throwError('ERROR!');
fixturePushPipeTestComponent.detectChanges();
expect(errorHandler.handleError).toHaveBeenCalledWith('ERROR!');
});
Expand Down Expand Up @@ -290,7 +290,7 @@ describe('PushPipe', () => {
pushPipeTestComponent.value$ = of(10);
fixturePushPipeTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe(wrapWithSpace('10'));
pushPipeTestComponent.value$ = throwError(() => 'ERROR!');
pushPipeTestComponent.value$ = throwError('ERROR!');
fixturePushPipeTestComponent.detectChanges();
expect(componentNativeElement.textContent).toBe(
wrapWithSpace('undefined')
Expand Down
4 changes: 2 additions & 2 deletions modules/data/spec/effects/entity-effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,10 @@ export class TestDataService {

setErrorResponse(methodName: keyof TestDataServiceMethod, error: any) {
// Following won't quite work because delay does not appear to delay an error
// this[methodName].and.returnValue(throwError(() => error).pipe(delay(1)));
// this[methodName].and.returnValue(throwError(error).pipe(delay(1)));
// Use timer instead
this[methodName].and.returnValue(
timer(1).pipe(mergeMap(() => throwError(() => error)))
timer(1).pipe(mergeMap(() => throwError(error)))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,10 @@ export class TestDataService {

setErrorResponse(methodName: keyof TestDataServiceMethod, error: any) {
// Following won't quite work because delay does not appear to delay an error
// this[methodName].and.returnValue(throwError(() => error).pipe(delay(1)));
// this[methodName].and.returnValue(throwError(error).pipe(delay(1)));
// Use timer instead
this[methodName].and.returnValue(
timer(1).pipe(mergeMap(() => throwError(() => error)))
timer(1).pipe(mergeMap(() => throwError(error)))
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/data/src/dataservices/entity-cache-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class EntityCacheDataService {
protected handleError(reqData: RequestData) {
return (err: any) => {
const error = new DataServiceError(err, reqData);
return throwError(() => error);
return throwError(error);
};
}

Expand Down
2 changes: 1 addition & 1 deletion modules/data/src/dispatchers/entity-cache-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class EntityCacheDispatcher {
)
: act.type === EntityCacheAction.SAVE_ENTITIES_SUCCESS
? of((act as SaveEntitiesSuccess).payload.changeSet)
: throwError(() => (act as SaveEntitiesError).payload);
: throwError((act as SaveEntitiesError).payload);
})
);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/data/src/dispatchers/entity-dispatcher-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ export class EntityDispatcherBase<T> implements EntityDispatcher<T> {
mergeMap((act) => {
const { entityOp } = act.payload;
return entityOp === EntityOp.CANCEL_PERSIST
? throwError(() => new PersistanceCanceled(act.payload.data))
? throwError(new PersistanceCanceled(act.payload.data))
: entityOp.endsWith(OP_SUCCESS)
? of(act.payload.data as D)
: throwError(() => act.payload.data.error);
: throwError(act.payload.data.error);
})
);
}
Expand Down
6 changes: 2 additions & 4 deletions modules/effects/spec/act.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('act operator', () => {

it('should call the error callback when error in the project occurs', () => {
const sources$ = hot(' -a', genActions('a'));
const project = () => throwError(() => 'error');
const project = () => throwError('error');
const error = () => createAction('e')();
const expected$ = cold('-e', genActions('e'));

Expand All @@ -97,9 +97,7 @@ describe('act operator', () => {
it('should continue listen to the sources actions after error occurs', () => {
const sources$ = hot('-a--b', genActions('ab'));
const project = (action: Action) =>
action.type === 'a'
? throwError(() => 'error')
: cold('(v|)', genActions('v'));
action.type === 'a' ? throwError('error') : cold('(v|)', genActions('v'));
const error = () => createAction('e')();
// error handler action is dispatched and next action with type b is also
// handled
Expand Down
4 changes: 2 additions & 2 deletions modules/effects/spec/effect_sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('EffectSources', () => {
}

class SourceError {
@Effect() e$ = throwError(() => error);
@Effect() e$ = throwError(error);
}

class SourceH {
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('EffectSources', () => {
}

class SourceError {
e$ = createEffect(() => throwError(() => error) as any);
e$ = createEffect(() => throwError(error) as any);
}

class SourceH {
Expand Down
2 changes: 1 addition & 1 deletion modules/effects/spec/effects_error_handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Effects Error Handler', () => {
}

class AlwaysErrorEffect {
effect$ = createEffect(() => throwError(() => 'always an error') as any);
effect$ = createEffect(() => throwError('always an error') as any);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ export class FakeBackendInterceptor implements HttpInterceptor {
storyId = url.split('/').pop();

if (!storyId) {
return throwError(() => new HttpErrorResponse({ status: 400 }));
return throwError(new HttpErrorResponse({ status: 400 }));
}

const obj = data[storyId];
if (obj) {
return of(new HttpResponse({ status: 200, body: obj }));
}

return throwError(() => new HttpErrorResponse({ status: 404 }));
return throwError(new HttpErrorResponse({ status: 404 }));

case 'POST':
storyId = Date.now().toString();
Expand All @@ -58,11 +58,11 @@ export class FakeBackendInterceptor implements HttpInterceptor {
storyId = url.split('/').pop();

if (!storyId) {
return throwError(() => new HttpErrorResponse({ status: 400 }));
return throwError(new HttpErrorResponse({ status: 400 }));
}

if (!data[storyId]) {
return throwError(() => new HttpErrorResponse({ status: 404 }));
return throwError(new HttpErrorResponse({ status: 404 }));
}

data[storyId] = {
Expand All @@ -77,15 +77,15 @@ export class FakeBackendInterceptor implements HttpInterceptor {
storyId = url.split('/').pop();

if (!storyId) {
return throwError(() => new HttpErrorResponse({ status: 400 }));
return throwError(new HttpErrorResponse({ status: 400 }));
}

delete data[storyId];

return of(new HttpResponse({ status: 200, body: storyId }));

default:
return throwError(() => new HttpErrorResponse({ status: 501 }));
return throwError(new HttpErrorResponse({ status: 501 }));
}
}
}
2 changes: 1 addition & 1 deletion projects/example-app/src/app/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AuthService {
* message for the login form.
*/
if (username !== 'test' && username !== 'ngrx') {
return throwError(() => 'Invalid username or password');
return throwError('Invalid username or password');
}

return of({ name: 'User' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class BookStorageService {
supported(): Observable<boolean> {
return this.storage !== null
? of(true)
: throwError(() => 'Local Storage Not Supported');
: throwError('Local Storage Not Supported');
}

getCollection(): Observable<Book[]> {
Expand Down
2 changes: 1 addition & 1 deletion projects/ngrx.io/content/guide/effects/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function effectResubscriptionHandler&gt;T extends Action&lt;(
}

errorHandler.handleError(e);
return throwError(() => e);
return throwError(e);
})
)
)
Expand Down

0 comments on commit 430a23f

Please sign in to comment.