Skip to content

Commit

Permalink
feat: add extra error handle
Browse files Browse the repository at this point in the history
  • Loading branch information
mfteloglu committed Jan 12, 2024
1 parent e3c15ae commit 8be8897
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 6 additions & 3 deletions parma_mining/github/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from parma_mining.github.normalization_map import GithubNormalizationMap
from parma_mining.mining_common.exceptions import (
AnalyticsError,
ClientInvalidBodyError,
CrawlingError,
)

Expand Down Expand Up @@ -87,7 +88,7 @@ def get_organization_details(body: CompaniesRequest):
logger.error(
f"Can't fetch company details from GitHub. Error: {e}"
)
errors = collect_errors(company_id, errors, e)
collect_errors(company_id, errors, e)
continue

data = ResponseModel(
Expand All @@ -102,10 +103,12 @@ def get_organization_details(body: CompaniesRequest):
logger.error(
f"Can't send crawling data to the Analytics. Error: {e}"
)
errors = collect_errors(company_id, errors, e)
collect_errors(company_id, errors, e)

else:
logger.error(f"Unsupported type error for {data_type} in {handle}")
msg = f"Unsupported type error for {data_type} in {handle}"
logger.error(msg)
collect_errors(company_id, errors, ClientInvalidBodyError(msg))

return analytics_client.crawling_finished(
json.loads(
Expand Down
5 changes: 2 additions & 3 deletions parma_mining/github/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from parma_mining.mining_common.exceptions import BaseError


def collect_errors(company_id: str, errors: dict, e: BaseError) -> dict:
"""Collect errors to return analytics."""
def collect_errors(company_id: str, errors: dict, e: BaseError):
"""Collect errors in required dict format."""
errors[company_id] = ErrorInfoModel(
error_type=e.__class__.__name__, error_description=e.message
)
return errors
2 changes: 1 addition & 1 deletion parma_mining/github/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ErrorInfoModel(BaseModel):
"""Error info for the crawling_finished endpoint."""

error_type: str
error_description: str
error_description: str | None


class CrawlingFinishedInputModel(BaseModel):
Expand Down

0 comments on commit 8be8897

Please sign in to comment.