Skip to content

Commit

Permalink
Merge pull request #406 from truefoundry/fix/raise-on-get-error
Browse files Browse the repository at this point in the history
fix: fail data loader if cannot fetch document.
  • Loading branch information
mnvsk97 authored Nov 8, 2024
2 parents 40b900e + 65654de commit 2522503
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions backend/modules/dataloaders/web_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import aiohttp
from bs4 import BeautifulSoup
from fastapi import HTTPException

from backend.logger import logger
from backend.modules.dataloaders.loader import BaseDataLoader
Expand Down Expand Up @@ -118,10 +119,11 @@ async def load_filtered_data(
if extension != "url":
async with session.get(url) as response:
if response.status != 200:
logger.warning(
f"Failed to fetch {url}: Status {response.status}"
message = f"Failed to obtain data from {url}: Status {response.status}"
logger.error(message)
raise HTTPException(
status_code=response.status, message=message
)
continue
# Could have used path as per URL but that makes us vulnerable to path traversal attacks
with tempfile.NamedTemporaryFile(
delete=False, suffix=extension, dir=dest_dir, mode="wb"
Expand Down

0 comments on commit 2522503

Please sign in to comment.