@@ -27,20 +27,22 @@ private function parseData(Context $context): array
2727 $ body = (array ) $ context ->body ();
2828
2929 if (!isset ($ body ['data ' ]) || !is_array ($ body ['data ' ])) {
30- throw new BadRequestException ('data must be an object ' );
30+ throw new BadRequestException ('data must be an object ' , [ ' pointer ' => ' /data ' ] );
3131 }
3232
3333 if (!isset ($ body ['data ' ]['type ' ])) {
34- throw new BadRequestException ('data.type must be present ' );
34+ throw new BadRequestException ('data.type must be present ' , [ ' pointer ' => ' /data/type ' ] );
3535 }
3636
3737 if (isset ($ context ->model )) {
3838 if (!isset ($ body ['data ' ]['id ' ])) {
39- throw new BadRequestException ('data.id must be present ' );
39+ throw new BadRequestException ('data.id must be present ' , [ ' pointer ' => ' /data/id ' ] );
4040 }
4141
4242 if ($ body ['data ' ]['id ' ] !== $ context ->resource ->getId ($ context ->model , $ context )) {
43- throw new ConflictException ('data.id does not match the resource ID ' );
43+ throw new ConflictException ('data.id does not match the resource ID ' , [
44+ 'pointer ' => '/data/id ' ,
45+ ]);
4446 }
4547 } elseif (isset ($ body ['data ' ]['id ' ])) {
4648 throw new ForbiddenException ('Client-generated IDs are not supported ' );
@@ -51,11 +53,15 @@ private function parseData(Context $context): array
5153 }
5254
5355 if (isset ($ body ['data ' ]['attributes ' ]) && !is_array ($ body ['data ' ]['attributes ' ])) {
54- throw new BadRequestException ('data.attributes must be an object ' );
56+ throw new BadRequestException ('data.attributes must be an object ' , [
57+ 'pointer ' => '/data/attributes ' ,
58+ ]);
5559 }
5660
5761 if (isset ($ body ['data ' ]['relationships ' ]) && !is_array ($ body ['data ' ]['relationships ' ])) {
58- throw new BadRequestException ('data.relationships must be an object ' );
62+ throw new BadRequestException ('data.relationships must be an object ' , [
63+ 'pointer ' => '/data/relationships ' ,
64+ ]);
5965 }
6066
6167 return array_merge (['attributes ' => [], 'relationships ' => []], $ body ['data ' ]);
@@ -82,7 +88,9 @@ private function assertFieldsExist(Context $context, array $data): void
8288 foreach (['attributes ' , 'relationships ' ] as $ location ) {
8389 foreach ($ data [$ location ] as $ name => $ value ) {
8490 if (!isset ($ fields [$ name ]) || $ location !== location ($ fields [$ name ])) {
85- throw new BadRequestException ("Unknown field [ $ name] " );
91+ throw new BadRequestException ("Unknown field [ $ name] " , [
92+ 'pointer ' => "/data/ $ location/ $ name " ,
93+ ]);
8694 }
8795 }
8896 }
@@ -118,7 +126,13 @@ private function deserializeValues(Context $context, array &$data): void
118126
119127 $ value = get_value ($ data , $ field );
120128
121- set_value ($ data , $ field , $ field ->deserializeValue ($ value , $ context ));
129+ try {
130+ set_value ($ data , $ field , $ field ->deserializeValue ($ value , $ context ));
131+ } catch (BadRequestException $ e ) {
132+ throw $ e ->prependSource ([
133+ 'pointer ' => '/data/ ' . location ($ field ) . '/ ' . $ field ->name ,
134+ ]);
135+ }
122136 }
123137 }
124138
0 commit comments