Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix: return 400 on fetch rejection in public /upload-from-url

Gilad Resisic96935a0efe3
diff --git a/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts b/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts
index 1111d2aff..5cb53b90d 100644
--- a/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts
+++ b/apps/backend/src/public-api/routes/v1/public.integrations.controller.ts
@@ -103,10 +103,17 @@ export class PublicIntegrationsController {
@Body() body: UploadDto
) {
Sentry.metrics.count('public_api-request', 1);
- const response = await fetch(body.url, {
- // @ts-ignore β€” undici option, not in lib.dom fetch types
- dispatcher: ssrfSafeDispatcher,
- });
+ let response: globalThis.Response;
+ try {
+ response = await fetch(body.url, {
+ // @ts-ignore β€” undici option, not in lib.dom fetch types
+ dispatcher: ssrfSafeDispatcher,
+ });
+ } catch {
+ // Network-level failure (DNS, connection refused, SSRF block, etc.) β€”
+ // fetch rejects rather than returning a non-ok response.
+ throw new HttpException({ msg: 'Failed to fetch URL' }, 400);
+ }
if (!response.ok) {
throw new HttpException({ msg: 'Failed to fetch URL' }, 400);
}