Skip to content

Commit

Permalink
BI-5240: Add custom error for invalid yados link prefix (#279) (#292)
Browse files Browse the repository at this point in the history
* BI-5240: Add custom error for invalid yados link prefix

* BI-5240: Add custom error for invalid yados link prefix

---------

Co-authored-by: vallbull <[email protected]>
Co-authored-by: Valeria Bulanova <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent 9edb80a commit 259d2f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

from dl_constants.enums import FileProcessingStatus
from dl_file_uploader_lib.enums import FileType
from dl_file_uploader_lib.exc import InvalidLink
from dl_file_uploader_lib.exc import (
InvalidLink,
YaDocsInvalidLinkPrefix,
)
from dl_file_uploader_lib.redis_model.base import RedisModelManager
from dl_file_uploader_lib.redis_model.models import DataFile
from dl_file_uploader_lib.redis_model.models.models import (
Expand Down Expand Up @@ -84,7 +87,9 @@ async def yadocs_data_file_preparer(
path = parts.path
prefix = "/i/"
if not path.startswith(prefix):
raise InvalidLink(f"Invalid URL path prefix: {path!r}; should be {prefix!r}; {example_url_message}")
raise YaDocsInvalidLinkPrefix(
f"Invalid URL path prefix: {path!r}; should be {prefix!r}; {example_url_message}"
)

df = DataFile(
manager=redis_model_manager,
Expand Down
5 changes: 5 additions & 0 deletions lib/dl_file_uploader_lib/dl_file_uploader_lib/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class InvalidLink(DLFileUploaderBaseError):
default_message = "Invalid format link provided"


class YaDocsInvalidLinkPrefix(InvalidLink):
err_code = InvalidLink.err_code + ["YADOCS_INVALID_PUBLIC_LINK_PREFIX"]
default_message = "Invalid url path prefix"


class EmptyDocument(DLFileUploaderBaseError):
err_code = DLFileUploaderBaseError.err_code + ["NO_DATA"]
default_message = "Empty document"
Expand Down

0 comments on commit 259d2f9

Please sign in to comment.