Skip to content

Commit 2c717d3

Browse files
Merge pull request #2511 from asfadmin/will/catch-search-errors
Catch SBAS search errors when granule doesn't have baseline
2 parents 712fe7f + b66fa63 commit 2c717d3

2 files changed

Lines changed: 22 additions & 30 deletions

File tree

src/app/components/shared/search-button/search-button.component.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class SearchButtonComponent implements OnInit, OnDestroy {
106106
);
107107

108108
public isLoggedIn = false;
109-
public searchError$ = new Subject<void>();
109+
public searchError$ = new Subject<searchStore.SearchError>();
110110
public isSearchError = false;
111111
public isFiltersOpen = false;
112112

@@ -142,7 +142,7 @@ export class SearchButtonComponent implements OnInit, OnDestroy {
142142
searchStore.SearchActionType.SEARCH_ERROR,
143143
),
144144
)
145-
.subscribe((_) => this.onSearchError()),
145+
.subscribe((error) => this.onSearchError(error)),
146146
);
147147

148148
this.subs.add(
@@ -220,13 +220,11 @@ export class SearchButtonComponent implements OnInit, OnDestroy {
220220
this.subs.add(
221221
this.searchError$
222222
.pipe(
223-
tap((_) => {
223+
tap((error) => {
224+
const errorMessage =
225+
error.payload || 'Trouble loading search results';
224226
this.isSearchError = true;
225-
this.notificationService.error(
226-
'Trouble loading search results',
227-
'Search Error',
228-
{ timeOut: 5000 },
229-
);
227+
this.notificationService.error(errorMessage, 'Search Error');
230228
}),
231229
delay(820),
232230
)
@@ -236,8 +234,8 @@ export class SearchButtonComponent implements OnInit, OnDestroy {
236234
);
237235
}
238236

239-
public onSearchError(): void {
240-
this.searchError$.next();
237+
public onSearchError(error: searchStore.SearchError): void {
238+
this.searchError$.next(error);
241239
}
242240

243241
public saveCurrentSearch(): void {

src/app/store/search/search.effect.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Injectable, inject } from '@angular/core';
33
import { Actions, createEffect, ofType } from '@ngrx/effects';
44
import { Store, Action } from '@ngrx/store';
55

6-
import { of, forkJoin, combineLatest, Observable, EMPTY } from 'rxjs';
6+
import { of, forkJoin, combineLatest, Observable } from 'rxjs';
77
import {
88
map,
99
withLatestFrom,
@@ -198,11 +198,21 @@ export class SearchEffects {
198198
return this.customProductsQuery$();
199199
} else if (searchType === SearchType.DISPLACEMENT) {
200200
return this.timeseriesQuery$();
201+
} else {
202+
this.logCountries();
203+
return this.asfApiQuery$;
204+
}
205+
}),
206+
catchError((err: HttpErrorResponse) => {
207+
const errorMsg = err?.error?.error?.report;
208+
if (errorMsg) {
209+
return of(new SearchError(errorMsg));
210+
}
211+
if (err.status !== 400) {
212+
return of(new SearchError('Unknown Error'));
201213
}
202214

203-
this.logCountries();
204-
205-
return this.asfApiQuery$;
215+
return of(new SearchError('Error loading search results'));
206216
}),
207217
),
208218
);
@@ -599,12 +609,6 @@ export class SearchEffects {
599609
})
600610
: new SearchCanceled(),
601611
),
602-
catchError((err: HttpErrorResponse) => {
603-
if (err.status !== 400) {
604-
return of(new SearchError('Unknown Error'));
605-
}
606-
return EMPTY;
607-
}),
608612
),
609613
),
610614
);
@@ -632,12 +636,6 @@ export class SearchEffects {
632636
})
633637
: new SearchCanceled();
634638
}),
635-
catchError((err: HttpErrorResponse) => {
636-
if (err.status !== 400) {
637-
return of(new SearchError('Unknown Error'));
638-
}
639-
return EMPTY;
640-
}),
641639
);
642640
}),
643641
);
@@ -662,10 +660,6 @@ export class SearchEffects {
662660
})
663661
: new SearchCanceled(),
664662
),
665-
catchError((error) => {
666-
console.log(error);
667-
return of(new SearchError('Error loading search results'));
668-
}),
669663
);
670664
}
671665

0 commit comments

Comments
 (0)