From e0d043456bdf2015e4b2e021b25e6a9b33bcb25b Mon Sep 17 00:00:00 2001 From: Yevhen Pokras Date: Thu, 17 Apr 2025 18:32:01 +0300 Subject: [PATCH] fix: decode OpenLibrary author response before accessing fields The author response from the OpenLibrary API was being treated as an array, but HttpClientInterface::request() returns a ResponseInterface. This caused a fatal error when trying to access `$author['name']`. Now the response content is properly decoded before accessing the 'name' field. --- api/src/BookRepository/OpenLibraryBookRepository.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/BookRepository/OpenLibraryBookRepository.php b/api/src/BookRepository/OpenLibraryBookRepository.php index a2ced9c3..29d279e8 100644 --- a/api/src/BookRepository/OpenLibraryBookRepository.php +++ b/api/src/BookRepository/OpenLibraryBookRepository.php @@ -36,7 +36,8 @@ public function find(string $url): ?Book $book->author = null; if (isset($data['authors'][0]['key'])) { - $author = $this->openLibraryClient->request('GET', $data['authors'][0]['key'] . '.json', $options); + $authorResponse = $this->openLibraryClient->request('GET', $data['authors'][0]['key'] . '.json', $options); + $author = $this->decoder->decode($authorResponse->getContent(), 'json'); if (isset($author['name'])) { $book->author = $author['name']; }