wrap get todays schedule in try catch
This commit is contained in:
parent
659f9b88f1
commit
f315db6d00
1 changed files with 21 additions and 9 deletions
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace App\ScheduledNode;
|
||||
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\ScheduledNode\UseCases\GetTodaysSchedule;
|
||||
use App\ScheduledNode\UseCases\GetTodaysScheduleRequest;
|
||||
use App\User\User;
|
||||
use DomainException;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
|
|
@ -26,21 +28,31 @@ class ScheduledNodeController
|
|||
|
||||
$queryParams = $request->getQueryParams();
|
||||
$date = $queryParams['date'] ?? null;
|
||||
if ($date === null || $date === '') {
|
||||
if ($date === '') {
|
||||
$date = null;
|
||||
}
|
||||
|
||||
try {
|
||||
$scheduledNodes = $getTodaysSchedule->execute(
|
||||
new GetTodaysScheduleRequest(
|
||||
date: $date,
|
||||
userId: $user->getId(),
|
||||
)
|
||||
);
|
||||
} catch (BadRequestException $exception) {
|
||||
$response->getBody()->write(
|
||||
json_encode(['error' => 'date is required'])
|
||||
json_encode(['error' => $exception->getMessage()])
|
||||
);
|
||||
return $response->withStatus(400)
|
||||
->withHeader('Content-Type', 'application/json');
|
||||
} catch (DomainException $exception) {
|
||||
$response->getBody()->write(
|
||||
json_encode(['error' => $exception->getMessage()])
|
||||
);
|
||||
return $response->withStatus(404)
|
||||
->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
$scheduledNodes = $getTodaysSchedule->execute(
|
||||
new GetTodaysScheduleRequest(
|
||||
date: $date,
|
||||
userId: $user->getId(),
|
||||
)
|
||||
);
|
||||
|
||||
$data = array_values(array_map(
|
||||
function (ScheduledNode $scheduledNode) {
|
||||
return [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue