Skip to content

Commit

Permalink
feat: retry request 3 times on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
tylercchase committed Jan 27, 2025
1 parent ea1e36e commit 28fac14
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/app/services/netcdf-service.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BrowseOverlayService, NotificationService, WktService } from '@services';
import { Observable, Subject, catchError, first, map, of, tap } from 'rxjs';
import { Observable, Subject, catchError, delay, first, map, of, retryWhen, scan, tap } from 'rxjs';
// import WebGLTileLayer from 'ol/layer/WebGLTile';
import ImageLayer from 'ol/layer/Image';
// import Static from 'ol/source/ImageStatic';
Expand Down Expand Up @@ -92,6 +92,19 @@ export class NetcdfService {

return output
}
private handleRetry<T>(source: Observable<T>): Observable<T> {
return source.pipe(retryWhen(e => e.pipe(scan((errorCount, error) => {
if(error.status !== 0) {
throw error;
}
if (errorCount >= 3) {
throw error;
}
return errorCount + 1;
}, 0),
delay(1000)
)));
}

public getTimeSeries(geometry, flightDirection =FlightDirection.ASCENDING): Observable<any> {

Expand All @@ -111,6 +124,7 @@ export class NetcdfService {
"polarization": "VV",
// "flightDirection": flightDirection,
}, { responseType: 'json' }).pipe(
this.handleRetry,
first(),
catchError(error => {
this.notificationService.error(error.error.detail, 'Timeseries Service Error')
Expand Down

0 comments on commit 28fac14

Please sign in to comment.