Skip to content

feat/add error codes mapped to ingest library #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.19

* **Add more granular error response texts and codes**

## 0.0.18

* **Receive ingest 0.3.12**
Expand Down
2 changes: 1 addition & 1 deletion unstructured_platform_plugins/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.18" # pragma: no cover
__version__ = "0.0.19" # pragma: no cover
7 changes: 5 additions & 2 deletions unstructured_platform_plugins/etl_uvicorn/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from uvicorn.config import LOG_LEVELS
from uvicorn.importer import import_from_string

from unstructured_platform_plugins.etl_uvicorn.errors import wrap_error
from unstructured_platform_plugins.etl_uvicorn.otel import get_metric_provider, get_trace_provider
from unstructured_platform_plugins.etl_uvicorn.utils import (
get_func,
Expand Down Expand Up @@ -186,12 +187,14 @@ async def _stream_response():
)
except Exception as invoke_error:
logger.error(f"failed to invoke plugin: {invoke_error}", exc_info=True)
print(type(invoke_error))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want these prints right?

http_error = wrap_error(invoke_error)
print(http_error)
return InvokeResponse(
usage=usage,
filedata_meta=filedata_meta_model.model_validate(filedata_meta.model_dump()),
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
status_code_text=f"failed to invoke plugin: "
f"[{invoke_error.__class__.__name__}] {invoke_error}",
status_code_text=f"[{invoke_error.__class__.__name__}] {invoke_error}",
)

if input_schema_model.model_fields:
Expand Down
51 changes: 51 additions & 0 deletions unstructured_platform_plugins/etl_uvicorn/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from abc import ABC
from typing import Any, Optional

import unstructured_ingest.v2.errors as ingest_errors
from fastapi import HTTPException


class BaseError(HTTPException, ABC):
status_code: int

def __init__(self, detail: Any, headers: Optional[dict[str, str]] = None):
super().__init__(status_code=self.status_code, detail=detail, headers=headers)


class UserError(BaseError):
status_code: int = 400


class UserAuthError(UserError):
status_code: int = 403


class RateLimitError(UserError):
status_code: int = 429


class QuotaError(UserError):
status_code: int = 402


class ProviderError(BaseError):
status_code: int = 500


class CatchAllError(BaseError):
status_code: int = 512


def wrap_error(e: Exception) -> HTTPException:
if isinstance(e, ingest_errors.UserAuthError):
return UserAuthError(e)
elif isinstance(e, ingest_errors.RateLimitError):
return RateLimitError(e)
elif isinstance(e, ingest_errors.QuotaError):
return QuotaError(e)
elif isinstance(e, ingest_errors.UserError):
return UserError(e)
elif isinstance(e, ingest_errors.ProviderError):
return ProviderError(e)
else:
return CatchAllError(e)
Loading