Skip to content

Commit

Permalink
Fixed form validation exceptions to use 400 Bad Request instead of …
Browse files Browse the repository at this point in the history
…`500 Internal Server Error`
  • Loading branch information
mahagr committed Nov 12, 2021
1 parent 2a04628 commit d9c9f6a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Fixed unescaped error messages in JSON error responses
* Fixed `|t(variable)` twig filter in admin
* Fixed `FlexObject::getChanges()` always returning empty array
* Fixed form validation exceptions to use `400 Bad Request` instead of `500 Internal Server Error`

# v1.7.24
## 10/26/2021
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/Data/BlueprintSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function validate(array $data, array $options = [])
}

if (!empty($messages)) {
throw (new ValidationException())->setMessages($messages);
throw (new ValidationException('', 400))->setMessages($messages);
}
}

Expand Down Expand Up @@ -199,7 +199,7 @@ protected function validateArray(array $data, array $rules, bool $strict, bool $
/** @var Config $config */
$config = Grav::instance()['config'];
if (!$config->get('system.strict_mode.blueprint_strict_compat', true)) {
throw new RuntimeException(sprintf('%s is not defined in blueprints', $key));
throw new RuntimeException(sprintf('%s is not defined in blueprints', $key), 400);
}

user_error(sprintf('Having extra key %s in your data is deprecated with blueprint having \'validation: strict\'', $key), E_USER_DEPRECATED);
Expand Down

0 comments on commit d9c9f6a

Please sign in to comment.