Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Controller/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function validateCreateRequest(string $rawRequestContent, Response $resp
}

if (!$isValid) {
$response->setStatusCode(500);
$response->setStatusCode(400);
$response->setContent(json_encode($responseContent, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT));
}

Expand Down
30 changes: 30 additions & 0 deletions Documentation/Api/RestApi.apib
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ that require authentication.
"expiry": "2017-07-20T18:22:48+00:00"
}

+ Response 400 (application/json)

+ Body

{
"code": 1500559729794,
"message": "No data",
"description": "The request does not contain any data."
}

+ Response 400 (application/json)

+ Body

{
"code": 1500562402438,
"message": "Invalid JSON data",
"description": "The data in the request is invalid JSON."
}

+ Response 400 (application/json)

+ Body

{
"code": 1500562647846,
"message": "Incomplete credentials",
"description": "The request does not contain both loginName and password."
}

+ Response 401 (application/json)

+ Body
Expand Down
12 changes: 6 additions & 6 deletions Tests/Integration/Controller/SessionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public function getSessionsIsNotAllowed()
/**
* @test
*/
public function postSessionsWithNoJsonReturnsError500()
public function postSessionsWithNoJsonReturnsError400()
{
$this->client->request('post', '/api/v2/sessions');

$responseContent = $this->client->getResponse()->getContent();
$parsedResponseContent = json_decode($responseContent, true);

self::assertSame(500, $this->client->getResponse()->getStatusCode());
self::assertSame(400, $this->client->getResponse()->getStatusCode());
self::assertSame(
[
'code' => 1500559729794,
Expand All @@ -77,14 +77,14 @@ public function postSessionsWithNoJsonReturnsError500()
/**
* @test
*/
public function postSessionsWithInvalidJsonReturnsError500()
public function postSessionsWithInvalidJsonReturnsError400()
{
$this->client->request('post', '/api/v2/sessions', [], [], [], 'Here be dragons, but no JSON.');

$responseContent = $this->client->getResponse()->getContent();
$parsedResponseContent = json_decode($responseContent, true);

self::assertSame(500, $this->client->getResponse()->getStatusCode());
self::assertSame(400, $this->client->getResponse()->getStatusCode());
self::assertSame(
[
'code' => 1500562402438,
Expand Down Expand Up @@ -112,14 +112,14 @@ public function incompleteCredentialsDataProvider(): array
* @param string $jsonData
* @dataProvider incompleteCredentialsDataProvider
*/
public function postSessionsWithValidIncompleteJsonReturnsError500(string $jsonData)
public function postSessionsWithValidIncompleteJsonReturnsError400(string $jsonData)
{
$this->client->request('post', '/api/v2/sessions', [], [], [], $jsonData);

$responseContent = $this->client->getResponse()->getContent();
$parsedResponseContent = json_decode($responseContent, true);

self::assertSame(500, $this->client->getResponse()->getStatusCode());
self::assertSame(400, $this->client->getResponse()->getStatusCode());
self::assertSame(
[
'code' => 1500562647846,
Expand Down