refactor: add content type to all outgoing addTask responses

This commit is contained in:
Miguel Nogueira 2025-04-13 20:07:07 +01:00
parent f4894f40ce
commit 0e44c78af6

View File

@ -38,7 +38,7 @@ class TaskController
$this->builder->setErrorMessage('Malformed request payload. Please try again.'); $this->builder->setErrorMessage('Malformed request payload. Please try again.');
$this->builder->setErrorCode(400); $this->builder->setErrorCode(400);
$errorResponse = $response->withStatus(400, 'Invalid payload'); $errorResponse = $response->withStatus(400, 'Invalid payload')->withHeader('Content-Type', 'application/json');
$errorResponse->getBody()->write($this->builder->build()); $errorResponse->getBody()->write($this->builder->build());
return $errorResponse; return $errorResponse;
@ -57,7 +57,7 @@ class TaskController
$this->builder->setErrorMessage("The following parameters are missing: " . implode(', ', $missingKeys)); $this->builder->setErrorMessage("The following parameters are missing: " . implode(', ', $missingKeys));
$this->builder->setErrorCode(400); $this->builder->setErrorCode(400);
$errorResponse = $response->withStatus('400', 'Missing arguments'); $errorResponse = $response->withStatus('400', 'Missing arguments')->withHeader('Content-Type', 'application/json');
$errorResponse->getBody()->write($this->builder->build()); $errorResponse->getBody()->write($this->builder->build());
return $errorResponse; return $errorResponse;
@ -78,7 +78,7 @@ class TaskController
$this->builder->setErrorMessage($exception->getMessage()); $this->builder->setErrorMessage($exception->getMessage());
$this->builder->setErrorCode(400); $this->builder->setErrorCode(400);
$errorResponse = $response->withStatus(400); $errorResponse = $response->withStatus(400)->withHeader('Content-Type', 'application/json');
$errorResponse->getBody()->write($this->builder->build()); $errorResponse->getBody()->write($this->builder->build());
return $errorResponse; return $errorResponse;
@ -89,7 +89,7 @@ class TaskController
$this->builder->setErrorCode(400); $this->builder->setErrorCode(400);
$this->builder->setErrorMessage('Invalid task status code. Status must range from 1-4 (started, in progress, blocked, completed).'); $this->builder->setErrorMessage('Invalid task status code. Status must range from 1-4 (started, in progress, blocked, completed).');
$errorResponse = $response->withStatus(400); $errorResponse = $response->withStatus(400)->withHeader('Content-Type', 'application/json');
$errorResponse->getBody()->write($this->builder->build()); $errorResponse->getBody()->write($this->builder->build());
return $errorResponse; return $errorResponse;
@ -108,13 +108,13 @@ class TaskController
->setErrorMessage('An unexpected error has occurred whilst trying to perform this operation.') ->setErrorMessage('An unexpected error has occurred whilst trying to perform this operation.')
->setErrorCode(500); ->setErrorCode(500);
$errorResponse = $response->withStatus(500); $errorResponse = $response->withStatus(500)->withHeader('Content-Type', 'application/json');
$errorResponse->getBody()->write($this->builder->build()); $errorResponse->getBody()->write($this->builder->build());
return $errorResponse; return $errorResponse;
} }
$createdResponse = $response->withStatus(201); $createdResponse = $response->withStatus(201)->withHeader('Content-Type', 'application/json');
$this->builder->setOptionalMessage('Task created.') $this->builder->setOptionalMessage('Task created.')
->setPayload($task->persist()); ->setPayload($task->persist());