Check that rel="self" exists before attempting to get a member of "undefined"
authorDenis Laxalde <denis.laxalde@logilab.fr>
Tue, 23 May 2017 11:26:35 +0200
changeset 216 29ef6742d635
parent 215 bdde73b3869e
child 217 67419e09a231
Check that rel="self" exists before attempting to get a member of "undefined"
src/services/hypermedia.js
--- a/src/services/hypermedia.js	Tue May 23 10:37:37 2017 +0200
+++ b/src/services/hypermedia.js	Tue May 23 11:26:35 2017 +0200
@@ -46,7 +46,13 @@
     }
 
     getSubmissionSchema(resource) {
-        const selfLink = resource.data.getLink('self').rawLink;
+        let selfLink = resource.data.getLink('self');
+        if (selfLink) {
+            selfLink = selfLink.rawLink;
+        } else {
+            const err = new Error(`no rel="self" link found schema for ${resource.url}`);
+            return Promise.reject(err);
+        }
         const submissionSchema = selfLink.submissionSchema;
         if (submissionSchema.hasOwnProperty('$ref')) {
             return this.getSchema(submissionSchema.$ref);