diff --git a/src/Models/Api/Client.php b/src/Models/Api/Client.php index abe0814..360bbcf 100644 --- a/src/Models/Api/Client.php +++ b/src/Models/Api/Client.php @@ -8,6 +8,7 @@ use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\ServerException; use GuzzleHttp\RequestOptions; +use Nette\Http\IResponse; use Nette\Utils\Json; use Tracy\Debugger; use Tracy\ILogger; @@ -169,6 +170,12 @@ public function getMailLogs(?string $email, ?string $filter, ?int $limit, ?int $ $records[$i]->sent_at = new \DateTime($row->sent_at); } return $records; + } catch (ClientException $e) { + if ($e->getResponse()->getStatusCode() == IResponse::S400_BAD_REQUEST) { + Debugger::log($e, ILogger::ERROR); + return null; + } + throw $e; } catch (ServerException | ConnectException $e) { Debugger::log($e, ILogger::ERROR); return null; @@ -195,6 +202,12 @@ public function countMailLogs(string $email, array $statuses, ?\DateTime $from, ]); return Json::decode($logsCount->getBody()->getContents(), true); + } catch (ClientException $e) { + if ($e->getResponse()->getStatusCode() == IResponse::S400_BAD_REQUEST) { + Debugger::log($e, ILogger::ERROR); + return null; + } + throw $e; } catch (ServerException | ConnectException $e) { Debugger::log($e, ILogger::ERROR); return null; @@ -337,9 +350,13 @@ public function getUserPreferences($userId, $email, ?bool $subscribed = null) return Json::decode($result->getBody(), Json::FORCE_ARRAY); } catch (ClientException $e) { - if ($e->getResponse()->getStatusCode() == 404) { + if ($e->getResponse()->getStatusCode() == IResponse::S404_NOT_FOUND) { return []; } + if ($e->getResponse()->getStatusCode() == IResponse::S400_BAD_REQUEST) { + Debugger::log($e, ILogger::ERROR); + return null; + } throw $e; } catch (ServerException | ConnectException $e) { Debugger::log($e, ILogger::ERROR);