From ca98155373e759b65d2e62558c97a68f7158c704 Mon Sep 17 00:00:00 2001 From: Marc Hagen Date: Mon, 18 Sep 2023 20:04:59 +0200 Subject: [PATCH] fix: Actually check if we have correct data --- app/Uploads/UserAvatars.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Uploads/UserAvatars.php b/app/Uploads/UserAvatars.php index 9692b3f38..0cda31a1c 100644 --- a/app/Uploads/UserAvatars.php +++ b/app/Uploads/UserAvatars.php @@ -56,7 +56,7 @@ class UserAvatars /** * Destroy all user avatars uploaded to the given user. */ - public function destroyAllForUser(User $user) + public function destroyAllForUser(User $user): void { $profileImages = Image::query()->where('type', '=', 'user') ->where('uploaded_to', '=', $user->id) @@ -70,7 +70,7 @@ class UserAvatars /** * Save an avatar image from an external service. * - * @throws Exception + * @throws HttpFetchException */ protected function saveAvatarImage(User $user, int $size = 500): Image { @@ -114,12 +114,14 @@ class UserAvatars try { $client = $this->http->buildClient(5); $response = $client->sendRequest(new Request('GET', $url)); - $imageData = (string) $response->getBody(); + if ($response->getStatusCode() !== 200) { + throw new HttpFetchException(trans('errors.cannot_get_image_from_url', ['url' => $url])); + } + + return (string) $response->getBody(); } catch (ClientExceptionInterface $exception) { throw new HttpFetchException(trans('errors.cannot_get_image_from_url', ['url' => $url]), $exception->getCode(), $exception); } - - return $imageData; } /**