@@ -22,14 +22,22 @@ 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
+ } else {
28
+ const title = "The resources you provided could not be parsed." ;
29
+ const details = `The precise error was: "${ error . message } ".` ;
30
+ reject ( new APIError ( 400 , undefined , title , details ) ) ;
31
+ }
28
32
}
29
33
} ) ;
30
34
}
31
35
32
- function relationshipObjectFromJSON ( json ) {
36
+ function relationshipObjectFromJSON ( json , relationship ) {
37
+ if ( typeof json . data === 'undefined' ) {
38
+ throw new APIError ( 400 , undefined , `No data key was found for the '${ relationship } ' relationship.` )
39
+ }
40
+
33
41
return new RelationshipObject ( linkageFromJSON ( json . data ) ) ;
34
42
}
35
43
@@ -42,7 +50,7 @@ function resourceFromJSON(json) {
42
50
43
51
//build RelationshipObjects
44
52
for ( let key in relationships ) {
45
- relationships [ key ] = relationshipObjectFromJSON ( relationships [ key ] ) ;
53
+ relationships [ key ] = relationshipObjectFromJSON ( relationships [ key ] , key ) ;
46
54
}
47
55
48
56
return new Resource ( json . type , json . id , json . attributes , relationships , json . meta ) ;
0 commit comments