From 932f8190a7e6b3423843362131a69475b867b56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Sim=C3=A3o?= Date: Mon, 25 Sep 2023 14:15:04 -0300 Subject: [PATCH] fix: error when Notion sends an empty response (#290) Closes #289 --- CHANGELOG.md | 19 ++++++++++++++++++- src/Exceptions/ApiException.php | 6 +++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0ee0200..931ad7e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [v1.11.1] 2023-08-02 +## Fixed +- Error when Notion sends an empty response (#289) +### Build +- Bump brianium/paratest from 7.2.3 to 7.2.4 (#274) +- Bump vimeo/psalm from 5.14.0 to 5.14.1 (#275) +- Bump brianium/paratest from 7.2.4 to 7.2.5 (#277) +- Bump phpunit/phpunit from 10.3.1 to 10.3.2 (#278) +- Bump vimeo/psalm from 5.14.1 to 5.15.0 (#279) +- Bump guzzlehttp/guzzle from 7.7.0 to 7.8.0 (#280) +- Bump brianium/paratest from 7.2.5 to 7.2.6 (#283) +- Bump phpunit/phpunit from 10.3.2 to 10.3.3 (#284) +- Bump phpunit/phpunit from 10.3.3 to 10.3.4 (#286) +- Bump brianium/paratest from 7.2.6 to 7.2.7 (#288) +- Bump infection/infection from 0.27.0 to 0.27.2 (#287) + ## [v1.11.0] 2023-08-02 ### Added @@ -400,4 +416,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [1.9.0]: https://github.com/mariosimao/notion-sdk-php/releases/tag/v1.9.0 [1.10.0]: https://github.com/mariosimao/notion-sdk-php/releases/tag/v1.10.0 [1.11.0]: https://github.com/mariosimao/notion-sdk-php/releases/tag/v1.11.0 -[Unreleased]: https://github.com/mariosimao/notion-sdk-php/compare/v1.11.0...HEAD +[1.11.1]: https://github.com/mariosimao/notion-sdk-php/releases/tag/v1.11.1 +[Unreleased]: https://github.com/mariosimao/notion-sdk-php/compare/v1.11.1...HEAD diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 5fba69ba..1a5f3879 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -25,9 +25,13 @@ final public function __construct( final public static function fromResponse(ResponseInterface $response): static { - /** @var array{ message: string, code: string} $body */ + /** @var array{ message: string, code: string}|false|null $body */ $body = json_decode((string) $response->getBody(), true); + if ($body === null || $body === false) { + return new static("", "", $response); + } + return match ($body["code"]) { "conflict_error" => new ConflictException($body["message"], $body["code"], $response), default => new static($body["message"], $body["code"], $response),