From 461d5ec3286abe1bded05b412c6842eda639c3da Mon Sep 17 00:00:00 2001 From: vallbull <33630435+vallbull@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:01:34 +0300 Subject: [PATCH] BI-5240: Add custom error for invalid yados link prefix (#279) * BI-5240: Add custom error for invalid yados link prefix * BI-5240: Add custom error for invalid yados link prefix --------- Co-authored-by: Valeria Bulanova --- .../dl_file_uploader_api_lib/data_file_preparer.py | 9 +++++++-- lib/dl_file_uploader_lib/dl_file_uploader_lib/exc.py | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/dl_file_uploader_api_lib/dl_file_uploader_api_lib/data_file_preparer.py b/lib/dl_file_uploader_api_lib/dl_file_uploader_api_lib/data_file_preparer.py index bf708a765..da42b4ba4 100644 --- a/lib/dl_file_uploader_api_lib/dl_file_uploader_api_lib/data_file_preparer.py +++ b/lib/dl_file_uploader_api_lib/dl_file_uploader_api_lib/data_file_preparer.py @@ -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 ( @@ -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, diff --git a/lib/dl_file_uploader_lib/dl_file_uploader_lib/exc.py b/lib/dl_file_uploader_lib/dl_file_uploader_lib/exc.py index fee2049ed..7bdc3797a 100644 --- a/lib/dl_file_uploader_lib/dl_file_uploader_lib/exc.py +++ b/lib/dl_file_uploader_lib/dl_file_uploader_lib/exc.py @@ -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"