File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 22
33namespace JsonApiException \Error ;
44
5+ use Cake \Utility \Hash ;
56use Cake \Error \ExceptionRenderer ;
7+ use JsonApiException \Error \Exception \JsonApiException ;
68
79class JsonApiExceptionRenderer extends ExceptionRenderer
810{
9- public function jsonApi ($ exception )
11+ public function jsonApi (JsonApiException $ error )
1012 {
1113 $ response = $ this ->controller ->getResponse ();
14+ $ data = [
15+ 'message ' => $ error ->getMessage (),
16+ 'url ' => $ this ->controller ->getRequest ()->getRequestTarget (),
17+ 'line ' => $ error ->getLine (),
18+ 'errorCount ' => count (Hash::flatten ($ error ->getRequestErrors ())),
19+ 'errors ' => $ error ->getRequestErrors (),
20+ ];
21+
1222 return $ response
13- ->withStringBody (json_encode ([ ' errors ' => $ exception -> getRequestErrors ()] ))
14- ->withStatus (406 )
23+ ->withStringBody (json_encode ($ data ))
24+ ->withStatus ($ error -> getCode () )
1525 ->withType ('application/json ' );
1626 }
1727}
You can’t perform that action at this time.
0 commit comments