From d8843c578fdd13781ad608b91218d2147d823641 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio.bekerle@tugraz.at> Date: Fri, 26 Jul 2019 12:54:38 +0200 Subject: [PATCH] Add more error handling --- packages/common/jsonld.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/common/jsonld.js b/packages/common/jsonld.js index 3ab916fe..a259b570 100644 --- a/packages/common/jsonld.js +++ b/packages/common/jsonld.js @@ -134,11 +134,23 @@ export default class JSONLD { } getApiUrlForIdentifier(identifier) { - return this.getEntityForIdentifier(identifier)["@entryPoint"]; + const entity = this.getEntityForIdentifier(identifier); + + if (entity === undefined || entity["@entryPoint"] === undefined) { + throw new Error(`Entity with identifier "${identifier}" not found!`); + } + + return entity["@entryPoint"]; } getApiUrlForEntityName(entityName) { - return this.getEntityForEntityName(entityName)["@entryPoint"]; + const entity = this.getEntityForEntityName(entityName); + + if (entity === undefined || entity["@entryPoint"] === undefined) { + throw new Error(`Entity "${entityName}" not found!`); + } + + return entity["@entryPoint"]; } getEntityNameForIdentifier(identifier) { -- GitLab