Add check that JSON request body exists when required

[MAILPOET-4135]
This commit is contained in:
Jan Jakes
2022-02-16 11:00:39 +01:00
committed by Veljko V
parent 8c7516eaba
commit 51d6b541e5
2 changed files with 16 additions and 1 deletions

View File

@@ -36,7 +36,13 @@ class Request {
}
public function getBody(): array {
return $this->wpRequest->get_json_params() ?? [];
$json = $this->wpRequest->get_json_params();
/* @phpstan-ignore-next-line hotfix for missing 'null' in WP annotation */
if ($json === null) {
throw Exceptions::apiNoJsonBody();
}
return $json;
}
public function getRawBody(): string {