|
@@ -1270,6 +1270,15 @@ class PHP_CRUD_API {
|
1270
|
1270
|
}
|
1271
|
1271
|
}
|
1272
|
1272
|
|
|
1273
|
+ protected function exitWith400($type) {
|
|
1274
|
+ if (isset($_SERVER['REQUEST_METHOD'])) {
|
|
1275
|
+ header('Content-Type:',true,400);
|
|
1276
|
+ die("The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications. ($type)");
|
|
1277
|
+ } else {
|
|
1278
|
+ throw new \Exception("Bad request ($type)");
|
|
1279
|
+ }
|
|
1280
|
+ }
|
|
1281
|
+
|
1273
|
1282
|
protected function exitWith422($object) {
|
1274
|
1283
|
if (isset($_SERVER['REQUEST_METHOD'])) {
|
1275
|
1284
|
header('Content-Type:',true,422);
|
|
@@ -1684,6 +1693,11 @@ class PHP_CRUD_API {
|
1684
|
1693
|
$input = false;
|
1685
|
1694
|
} else if ($data[0]=='{' || $data[0]=='[') {
|
1686
|
1695
|
$input = json_decode($data);
|
|
1696
|
+ $causeCode = json_last_error();
|
|
1697
|
+ if ($causeCode !== JSON_ERROR_NONE) {
|
|
1698
|
+ $errorString = "Error decoding input JSON. json_last_error code: " . $causeCode;
|
|
1699
|
+ $this->exitWith400($errorString);
|
|
1700
|
+ }
|
1687
|
1701
|
} else {
|
1688
|
1702
|
parse_str($data, $input);
|
1689
|
1703
|
foreach ($input as $key => $value) {
|