diff --git a/src/app/core/auth/auth-request.service.spec.ts b/src/app/core/auth/auth-request.service.spec.ts index 2afeb26b02..704922c5b5 100644 --- a/src/app/core/auth/auth-request.service.spec.ts +++ b/src/app/core/auth/auth-request.service.spec.ts @@ -111,7 +111,6 @@ describe(`AuthRequestService`, () => { body: undefined, options, })); - expect((service as any).fetchRequest).toHaveBeenCalledWith(requestID); }); }); }); @@ -151,7 +150,6 @@ describe(`AuthRequestService`, () => { body: { content: 'something' }, options, })); - expect((service as any).fetchRequest).toHaveBeenCalledWith(requestID); }); }); }); diff --git a/src/app/core/auth/auth-request.service.ts b/src/app/core/auth/auth-request.service.ts index 7fd93fb014..5c0c3340c7 100644 --- a/src/app/core/auth/auth-request.service.ts +++ b/src/app/core/auth/auth-request.service.ts @@ -58,7 +58,9 @@ export abstract class AuthRequestService { public postToEndpoint(method: string, body?: any, options?: HttpOptions): Observable> { const requestId = this.requestService.generateRequestId(); - this.halService.getEndpoint(this.linkName).pipe( + const endpoint$ = this.halService.getEndpoint(this.linkName); + + endpoint$.pipe( filter((href: string) => isNotEmpty(href)), map((endpointURL) => this.getEndpointByMethod(endpointURL, method)), distinctUntilChanged(), @@ -68,7 +70,9 @@ export abstract class AuthRequestService { this.requestService.send(request); }); - return this.fetchRequest(requestId); + return endpoint$.pipe( + switchMap(() => this.fetchRequest(requestId)), + ); } /** @@ -79,7 +83,9 @@ export abstract class AuthRequestService { public getRequest(method: string, options?: HttpOptions, ...linksToFollow: FollowLinkConfig[]): Observable> { const requestId = this.requestService.generateRequestId(); - this.halService.getEndpoint(this.linkName).pipe( + const endpoint$ = this.halService.getEndpoint(this.linkName); + + endpoint$.pipe( filter((href: string) => isNotEmpty(href)), map((endpointURL) => this.getEndpointByMethod(endpointURL, method, ...linksToFollow)), distinctUntilChanged(), @@ -89,7 +95,9 @@ export abstract class AuthRequestService { this.requestService.send(request); }); - return this.fetchRequest(requestId, ...linksToFollow); + return endpoint$.pipe( + switchMap(() => this.fetchRequest(requestId, ...linksToFollow)), + ); } /** * Factory function to create the request object to send. This needs to be a POST client side and