Better API response when request body is not valid JSON (references #126)

This commit is contained in:
Bernd Bestel
2019-01-05 20:39:22 +01:00
parent c042657dd8
commit f6cf26009d
2 changed files with 41 additions and 8 deletions

View File

@@ -32,6 +32,11 @@ class UsersApiController extends BaseApiController
try
{
if ($requestBody === null)
{
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
}
$this->UsersService->CreateUser($requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
return $this->ApiResponse(array('success' => true));
}