@@ -22,14 +22,24 @@ export default function(data, parseAsLinkage) {
22
22
}
23
23
24
24
catch ( error ) {
25
- const title = "The resources you provided could not be parsed." ;
26
- const details = `The precise error was: "${ error . message } ".` ;
27
- reject ( new APIError ( 400 , undefined , title , details ) ) ;
25
+ if ( error instanceof APIError ) {
26
+ reject ( error ) ;
27
+ }
28
+
29
+ else {
30
+ const title = "The resources you provided could not be parsed." ;
31
+ const details = `The precise error was: "${ error . message } ".` ;
32
+ reject ( new APIError ( 400 , undefined , title , details ) ) ;
33
+ }
28
34
}
29
35
} ) ;
30
36
}
31
37
32
38
function relationshipObjectFromJSON ( json ) {
39
+ if ( typeof json . data === "undefined" ) {
40
+ throw new APIError ( 400 , undefined , `Missing relationship linkage.` ) ;
41
+ }
42
+
33
43
return new RelationshipObject ( linkageFromJSON ( json . data ) ) ;
34
44
}
35
45
@@ -41,8 +51,15 @@ function resourceFromJSON(json) {
41
51
let relationships = json . relationships || { } ;
42
52
43
53
//build RelationshipObjects
44
- for ( let key in relationships ) {
45
- relationships [ key ] = relationshipObjectFromJSON ( relationships [ key ] ) ;
54
+ let key ;
55
+ try {
56
+ for ( key in relationships ) {
57
+ relationships [ key ] = relationshipObjectFromJSON ( relationships [ key ] , key ) ;
58
+ }
59
+ }
60
+ catch ( e ) {
61
+ e . details = `No data was found for the ${ key } relationship.` ;
62
+ throw e ;
46
63
}
47
64
48
65
return new Resource ( json . type , json . id , json . attributes , relationships , json . meta ) ;
0 commit comments