From ee7cca24e7a6aa5fad040d76eb00e94c7cfbf236 Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Fri, 3 May 2024 15:05:24 +0200 Subject: [PATCH] feat: added catch for endpoint errors --- .../dataviz/src/lib/service/data.service.ts | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libs/feature/dataviz/src/lib/service/data.service.ts b/libs/feature/dataviz/src/lib/service/data.service.ts index 3e8d37488a..708905c488 100644 --- a/libs/feature/dataviz/src/lib/service/data.service.ts +++ b/libs/feature/dataviz/src/lib/service/data.service.ts @@ -174,8 +174,30 @@ export class DataService { async getDownloadUrlsFromOgcApi(url: string): Promise { const endpoint = new OgcApiEndpoint(this.proxy.getProxiedUrl(url)) - const collection = (await endpoint.featureCollections)[0] - return endpoint.getCollectionInfo(collection) + return await endpoint.featureCollections + .then((collections) => { + return endpoint.getCollectionInfo(collections[0]) + }) + .catch((error) => { + if (error instanceof Error) { + throw new Error(`wfs.unreachable.unknown`) + } else { + if (error.type === 'network') { + throw new Error(`wfs.unreachable.cors`) + } + if (error.type === 'http') { + throw new Error(`wfs.unreachable.http`) + } + if (error.type === 'parse') { + throw new Error(`wfs.unreachable.parse`) + } + if (error.type === 'unsupportedType') { + throw new Error(`wfs.unreachable.unsupportedType`) + } else { + throw new Error(`wfs.unreachable.unknown`) + } + } + }) } getDownloadLinksFromEsriRest(