Skip to content

Commit ca98155

Browse files
committed
fix: Actually check if we have correct data
1 parent ea75925 commit ca98155

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

app/Uploads/UserAvatars.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function assignToUserFromExistingData(User $user, string $imageData, stri
5656
/**
5757
* Destroy all user avatars uploaded to the given user.
5858
*/
59-
public function destroyAllForUser(User $user)
59+
public function destroyAllForUser(User $user): void
6060
{
6161
$profileImages = Image::query()->where('type', '=', 'user')
6262
->where('uploaded_to', '=', $user->id)
@@ -70,7 +70,7 @@ public function destroyAllForUser(User $user)
7070
/**
7171
* Save an avatar image from an external service.
7272
*
73-
* @throws Exception
73+
* @throws HttpFetchException
7474
*/
7575
protected function saveAvatarImage(User $user, int $size = 500): Image
7676
{
@@ -114,12 +114,14 @@ protected function getAvatarImageData(string $url): string
114114
try {
115115
$client = $this->http->buildClient(5);
116116
$response = $client->sendRequest(new Request('GET', $url));
117-
$imageData = (string) $response->getBody();
117+
if ($response->getStatusCode() !== 200) {
118+
throw new HttpFetchException(trans('errors.cannot_get_image_from_url', ['url' => $url]));
119+
}
120+
121+
return (string) $response->getBody();
118122
} catch (ClientExceptionInterface $exception) {
119123
throw new HttpFetchException(trans('errors.cannot_get_image_from_url', ['url' => $url]), $exception->getCode(), $exception);
120124
}
121-
122-
return $imageData;
123125
}
124126

125127
/**

0 commit comments

Comments
 (0)