diff --git a/src/app/my-dspace-page/my-dspace-page.component.html b/src/app/my-dspace-page/my-dspace-page.component.html index 4aadb16255..5a15abcc08 100644 --- a/src/app/my-dspace-page/my-dspace-page.component.html +++ b/src/app/my-dspace-page/my-dspace-page.component.html @@ -4,7 +4,7 @@ = new InjectionToken('searchConfigurationService'); @@ -111,8 +111,7 @@ export class MyDSpacePageComponent implements OnInit { constructor(private service: SearchService, private sidebarService: SidebarService, private windowService: HostWindowService, - @Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: MyDSpaceConfigurationService, - private routeService: RouteService) { + @Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: MyDSpaceConfigurationService) { this.isXsOrSm$ = this.windowService.isXsOrSm(); this.service.setServiceOptions(MyDSpaceResponseParsingService, MyDSpaceRequest); } @@ -134,8 +133,8 @@ export class MyDSpacePageComponent implements OnInit { this.searchOptions$ = this.searchConfigService.paginatedSearchOptions; this.sub = this.searchOptions$.pipe( tap(() => this.resultsRD$.next(null)), - switchMap((options: PaginatedSearchOptions) => this.service.search(options).pipe(getFirstSucceededRemoteData()))) - .subscribe((results) => { + switchMap((options: PaginatedSearchOptions) => this.service.search(options).pipe(getFirstCompletedRemoteData()))) + .subscribe((results: RemoteData>) => { this.resultsRD$.next(results); }); diff --git a/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.html b/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.html index 2710285f0d..67b13cc49c 100644 --- a/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.html +++ b/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.html @@ -10,5 +10,5 @@ - +

{{'mydspace.results.no-results' | translate}}

diff --git a/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.spec.ts b/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.spec.ts index 29a2e593de..5b069f4ddb 100644 --- a/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.spec.ts +++ b/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.spec.ts @@ -40,9 +40,19 @@ describe('MyDSpaceResultsComponent', () => { expect(fixture.debugElement.query(By.css('a'))).toBeNull(); }); - it('should display error message if error is != 400', () => { - (comp as any).searchResults = { hasFailed: true, error: { statusCode: 500 } }; + it('should display error message if error is 500', () => { + (comp as any).searchResults = { hasFailed: true, statusCode: 500 }; fixture.detectChanges(); + expect(comp.showError()).toBeTrue(); + expect(comp.errorMessageLabel()).toBe('error.search-results'); + expect(fixture.debugElement.query(By.css('ds-error'))).not.toBeNull(); + }); + + it('should display error message if error is 422', () => { + (comp as any).searchResults = { hasFailed: true, statusCode: 422 }; + fixture.detectChanges(); + expect(comp.showError()).toBeTrue(); + expect(comp.errorMessageLabel()).toBe('error.invalid-search-query'); expect(fixture.debugElement.query(By.css('ds-error'))).not.toBeNull(); }); diff --git a/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.ts b/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.ts index 32b6d9c9f7..77f27e9d42 100644 --- a/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.ts +++ b/src/app/my-dspace-page/my-dspace-results/my-dspace-results.component.ts @@ -58,4 +58,12 @@ export class MyDSpaceResultsComponent { isLoading() { return !this.searchResults || isEmpty(this.searchResults) || this.searchResults.isLoading; } + + showError(): boolean { + return this.searchResults?.hasFailed && (!this.searchResults?.errorMessage || this.searchResults?.statusCode !== 400); + } + + errorMessageLabel(): string { + return (this.searchResults?.statusCode === 422) ? 'error.invalid-search-query' : 'error.search-results'; + } } diff --git a/src/app/search-page/search.component.ts b/src/app/search-page/search.component.ts index 8be21af552..2972175bdf 100644 --- a/src/app/search-page/search.component.ts +++ b/src/app/search-page/search.component.ts @@ -8,7 +8,7 @@ import { pushInOut } from '../shared/animations/push'; import { HostWindowService } from '../shared/host-window.service'; import { SidebarService } from '../shared/sidebar/sidebar.service'; import { hasValue, isEmpty } from '../shared/empty.util'; -import { getFirstSucceededRemoteData } from '../core/shared/operators'; +import { getFirstCompletedRemoteData } from '../core/shared/operators'; import { RouteService } from '../core/services/route.service'; import { SEARCH_CONFIG_SERVICE } from '../my-dspace-page/my-dspace-page.component'; import { PaginatedSearchOptions } from '../shared/search/paginated-search-options.model'; @@ -126,12 +126,12 @@ export class SearchComponent implements OnInit { this.searchOptions$ = this.getSearchOptions(); this.sub = this.searchOptions$.pipe( switchMap((options) => this.service.search( - options, undefined, true, true, followLink('thumbnail', { isOptional: true }) - ).pipe(getFirstSucceededRemoteData(), startWith(undefined)) + options, undefined, false, true, followLink('thumbnail', { isOptional: true }) + ).pipe(getFirstCompletedRemoteData(), startWith(undefined)) ) ).subscribe((results) => { - this.resultsRD$.next(results); - }); + this.resultsRD$.next(results); + }); if (isEmpty(this.configuration$)) { this.configuration$ = this.searchConfigService.getCurrentConfiguration('default'); diff --git a/src/app/shared/error/error.component.html b/src/app/shared/error/error.component.html index d41760e258..157c47f2cd 100644 --- a/src/app/shared/error/error.component.html +++ b/src/app/shared/error/error.component.html @@ -1,3 +1,4 @@ -
- -
+ + + + diff --git a/src/app/shared/error/error.component.spec.ts b/src/app/shared/error/error.component.spec.ts index d3e3e80c07..f8483ac7aa 100644 --- a/src/app/shared/error/error.component.spec.ts +++ b/src/app/shared/error/error.component.spec.ts @@ -36,7 +36,7 @@ describe('ErrorComponent (inline template)', () => { comp = fixture.componentInstance; // ErrorComponent test instance // query for the message