Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Handle non-JSON error responses from CDN

Blue Mousebf5513317e5a
diff --git a/backend/apps/cloud/src/user/user.service.ts b/backend/apps/cloud/src/user/user.service.ts
index 77ea47932..371ee31f8 100644
--- a/backend/apps/cloud/src/user/user.service.ts
+++ b/backend/apps/cloud/src/user/user.service.ts
@@ -340,7 +340,13 @@ export class UserService {
throw new ServiceUnavailableException('Failed to upload attachments')
}
- const payload = await response.json()
+ let payload: unknown
+ try {
+ payload = await response.json()
+ } catch {
+ throw new ServiceUnavailableException('Invalid response from CDN')
+ }
+
return getCdnFiles(payload)
.map((file) => normaliseCdnUrl(baseUrl, file))
.filter((url): url is string => Boolean(url))