From 2a5b29543de5e651aad704365619237565aa16fe Mon Sep 17 00:00:00 2001 From: Shashank Mittal Date: Sun, 21 Jan 2024 13:53:39 +0530 Subject: [PATCH] error handling fixed, all tests passed. Signed-off-by: Shashank Mittal --- src/scribe_data/utils.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/scribe_data/utils.py b/src/scribe_data/utils.py index 7cec1b7eb..4c067ee50 100644 --- a/src/scribe_data/utils.py +++ b/src/scribe_data/utils.py @@ -158,11 +158,9 @@ def get_language_iso(language: str) -> str: """ try: iso_code = str(langcodes.find(language).language) - return iso_code - except langcodes.LanguageTagError: + except LookupError: raise ValueError(f"{language.capitalize()} is currently not a supported language for ISO conversion.") - - + return iso_code def get_language_from_iso(iso: str) -> str: """ @@ -178,11 +176,12 @@ def get_language_from_iso(iso: str) -> str: str The name for the language which has an ISO value of iso. """ - try: - language_name = str(Language.make(language=iso).display_name()) - return language_name - except langcodes.LanguageTagError: - raise ValueError(f"{iso} is currently not a supported ISO language.") + + language_name = str(Language.make(language=iso).display_name()) + if "Unknown language" in str(language_name): + raise ValueError(f"{iso.upper()} is currently not a supported ISO language.") + return language_name + def get_language_words_to_remove(language: str) -> list[str]: """