From 1d68e2619a74d7d8b2bd8faefbf01b9794f3a2f7 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 23 Feb 2022 10:07:45 +0100 Subject: Show error messages in action_image_restore If something goes wrong, the application shows an error message after redirecting to the commands view. Do not show blank pages with plain text error codes. --- ogcp/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ogcp/views.py b/ogcp/views.py index 99e7fa1..c60bd08 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -411,7 +411,8 @@ def action_image_restore(): images_list = r.json()['images'] image = search_image(images_list, int(image_id)) if not image: - return make_response("400 Bad Request", 400) + flash(_(f'Image to restore was not found'), category='error') + return redirect(url_for('commands')) payload = {'disk': disk, 'partition': partition, @@ -423,8 +424,10 @@ def action_image_restore(): 'id': str(image['id'])} g.server.post('/image/restore', payload) if r.status_code == requests.codes.ok: - return redirect(url_for('commands')) - return make_response("400 Bad Request", 400) + flash(_(f'Image restore command sent sucessfully'), category='info') + else: + flash(_(f'There was a problem sending the image restore command'), category='error') + return redirect(url_for('commands')) else: ips = parse_elements(request.args.to_dict()) if not validate_elements(ips): -- cgit v1.2.3-18-g5258