Skip to content

Commit

Permalink
refactor(record-downloads): catch OGC API error later
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed May 13, 2024
1 parent 3371b67 commit 62c6e68
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,26 @@ export class RecordDownloadsComponent {
return combineLatest([
...(wfsLinks.length > 0
? wfsLinks.map((link) =>
this.dataService.getDownloadLinksFromWfs(
link as DatasetServiceDistribution
)
this.dataService
.getDownloadLinksFromWfs(link as DatasetServiceDistribution)
.pipe(
catchError((e) => {
this.error = e.message
return [of([] as DatasetDistribution[])]
})
)
)
: [of([] as DatasetDistribution[])]),
...(ogcLinks.length > 0
? ogcLinks.map((link) =>
this.dataService.getDownloadLinksFromOgcApiFeatures(
link as DatasetServiceDistribution
)
this.dataService
.getDownloadLinksFromOgcApiFeatures(
link as DatasetServiceDistribution
)
.catch((e) => {
this.error = e.message
return Promise.resolve([])
})
)
: [of([] as DatasetDistribution[])]),
]).pipe(
Expand Down
32 changes: 13 additions & 19 deletions libs/feature/dataviz/src/lib/service/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,19 @@ export class DataService {
async getDownloadLinksFromOgcApiFeatures(
ogcApiLink: DatasetServiceDistribution
): Promise<DatasetDistribution[]> {
try {
const collectionInfo = await this.getDownloadUrlsFromOgcApi(
ogcApiLink.url.href
)
return Object.keys(collectionInfo.bulkDownloadLinks).map(
(downloadLink) => {
return {
...ogcApiLink,
type: 'download',
url: new URL(collectionInfo.bulkDownloadLinks[downloadLink]),
mimeType: getMimeTypeForFormat(
getFileFormatFromServiceOutput(downloadLink)
),
}
}
)
} catch (error) {
return Promise.resolve([])
}
const collectionInfo = await this.getDownloadUrlsFromOgcApi(
ogcApiLink.url.href
)
return Object.keys(collectionInfo.bulkDownloadLinks).map((downloadLink) => {
return {
...ogcApiLink,
type: 'download',
url: new URL(collectionInfo.bulkDownloadLinks[downloadLink]),
mimeType: getMimeTypeForFormat(
getFileFormatFromServiceOutput(downloadLink)
),
}
})
}

async getDownloadUrlsFromOgcApi(url: string): Promise<OgcApiCollectionInfo> {
Expand Down

0 comments on commit 62c6e68

Please sign in to comment.