diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2023-09-07 13:25:47 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-07 19:25:47 +0200 |
| commit | af96d720e9340e02b1ec6dafe10bf9a47e045804 (patch) | |
| tree | a49d9b1570050db02ff8f17b754e54ec7b9a6e1a /lib/api | |
| parent | 3db335b0f41ebfcc694914bba5bf81aed9ae98d4 (diff) | |
improve params errors (#2437)
Diffstat (limited to 'lib/api')
| -rw-r--r-- | lib/api/stitch_plan.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/api/stitch_plan.py b/lib/api/stitch_plan.py index c70efd98..5e9a57c1 100644 --- a/lib/api/stitch_plan.py +++ b/lib/api/stitch_plan.py @@ -5,9 +5,9 @@ from flask import Blueprint, g, jsonify +from ..exceptions import InkstitchException, format_uncaught_exception from ..stitch_plan import stitch_groups_to_stitch_plan - stitch_plan = Blueprint('stitch_plan', __name__) @@ -16,10 +16,14 @@ def get_stitch_plan(): if not g.extension.get_elements(): return dict(colors=[], stitch_blocks=[], commands=[]) - metadata = g.extension.get_inkstitch_metadata() - collapse_len = metadata['collapse_len_mm'] - min_stitch_len = metadata['min_stitch_len_mm'] - patches = g.extension.elements_to_stitch_groups(g.extension.elements) - stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) - - return jsonify(stitch_plan) + try: + metadata = g.extension.get_inkstitch_metadata() + collapse_len = metadata['collapse_len_mm'] + min_stitch_len = metadata['min_stitch_len_mm'] + patches = g.extension.elements_to_stitch_groups(g.extension.elements) + stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) + return jsonify(stitch_plan) + except InkstitchException as exc: + return jsonify({"error_message": str(exc)}), 500 + except Exception: + return jsonify({"error_message": format_uncaught_exception()}), 500 |
