diff --git a/.gitignore b/.gitignore index d3e9155..1a0b942 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ -# ignore config.json +# Ignore custom configuration file. config.json +# Ignore test files. +sample-out.png + ### Python template # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/brother_ql_web/web.py b/brother_ql_web/web.py index 35fb374..ce20a1e 100644 --- a/brother_ql_web/web.py +++ b/brother_ql_web/web.py @@ -88,7 +88,12 @@ def get_label_parameters( font_family = "" font_style = "" else: - raise + raise ValueError( + "Could not find valid font specifier. Please pass the `font_family` " + "parameter with the family and style in the format `Roboto (Medium)`, " + "where Roboto is the family name and Medium the corresponding font " + "style." + ) context = { "text": d.get("text", ""), "image": _save_to_bytes(request.files.get("image")), @@ -141,7 +146,7 @@ def print_text() -> dict[str, bool | str]: try: parameters = get_label_parameters(bottle.request) - except (AttributeError, LookupError) as e: + except (AttributeError, LookupError, ValueError) as e: return_dict["error"] = str(e) return return_dict @@ -169,7 +174,7 @@ def print_image() -> dict[str, bool | str]: try: parameters = get_label_parameters(bottle.request, should_be_file=True) - except (AttributeError, LookupError) as e: + except (AttributeError, LookupError, ValueError) as e: return_dict["error"] = str(e) return return_dict diff --git a/tests/test_web.py b/tests/test_web.py index 5986592..6bcdb29 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -245,7 +245,10 @@ def test_error(self) -> None: self.assertEqual( ( b'{"success": false, ' - b"\"error\": \"'NoneType' object has no attribute 'rpartition'\"}" + b'"error": "Could not find valid font specifier. ' + b'Please pass the `font_family` parameter with the family and style ' + b'in the format `Roboto (Medium)`, where Roboto is the family name ' + b'and Medium the corresponding font style."}' ), response.content, )