diff options
| author | rr- <rr-@sakuya.pl> | 2017-02-02 18:21:21 +0100 |
|---|---|---|
| committer | rr- <rr-@sakuya.pl> | 2017-02-02 19:46:03 +0100 |
| commit | aa1faa3ccbfbe8b5ee691a113aa52bce7e28ebba (patch) | |
| tree | 7c42704f5993fd126785f160d8bb4af7d1dbae80 /server/szurubooru/api/post_api.py | |
| parent | f42fbbdc5657686b1061a0d27666b9a4f395c88c (diff) | |
server/image-hash: improve exception handling
Diffstat (limited to 'server/szurubooru/api/post_api.py')
| -rw-r--r-- | server/szurubooru/api/post_api.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/server/szurubooru/api/post_api.py b/server/szurubooru/api/post_api.py index 5b38b18..cbf8f27 100644 --- a/server/szurubooru/api/post_api.py +++ b/server/szurubooru/api/post_api.py @@ -1,5 +1,5 @@ import datetime -from szurubooru import search, db +from szurubooru import search, db, errors from szurubooru.rest import routes from szurubooru.func import ( auth, tags, posts, snapshots, favorites, scores, util, versions) @@ -211,6 +211,12 @@ def get_posts_around(ctx, params): def get_posts_by_image(ctx, _params=None): auth.verify_privilege(ctx.user, 'posts:reverse_search') content = ctx.get_file('content', required=True) + + try: + lookalikes = posts.search_by_image(content) + except (errors.ThirdPartyError, errors.ProcessingError): + lookalikes = [] + return { 'exactPost': _serialize_post(ctx, posts.search_by_image_exact(content)), @@ -220,6 +226,6 @@ def get_posts_by_image(ctx, _params=None): 'distance': lookalike.distance, 'post': _serialize_post(ctx, lookalike.post), } - for lookalike in posts.search_by_image(content) + for lookalike in lookalikes ], } |