From f58b6dedaa27dda806a603ada3eada115a0404e3 Mon Sep 17 00:00:00 2001 From: hamid Date: Sun, 16 Jun 2019 15:46:54 +0400 Subject: [PATCH 1/4] Already shortened url message fixed --- pygmyui/pygmy/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pygmyui/pygmy/views.py b/pygmyui/pygmy/views.py index 7a966ab..e8adf59 100644 --- a/pygmyui/pygmy/views.py +++ b/pygmyui/pygmy/views.py @@ -61,8 +61,12 @@ def link_shortener(request): context=API_ERROR(e.args[0]), status=401) except (ObjectNotFound, InvalidInput) as e: + err = {} + err["error"] = (" ".join(API_ERROR(e.args[0])['error']) + if isinstance(API_ERROR(e.args[0])['error'],list) + else API_ERROR(e.args[0])['error']) return render(request, '400.html', - context=API_ERROR(e.args[0]), status=400) + context=err, status=400) short_code = resp['short_code'] else: return render( From b4b4a7326672e79fd2e2407b1065610816d82726 Mon Sep 17 00:00:00 2001 From: hamid Date: Fri, 21 Jun 2019 14:10:12 +0400 Subject: [PATCH 2/4] Already shortened URL error fixed --- pygmy/rest/shorturl.py | 2 +- pygmyui/pygmy/views.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pygmy/rest/shorturl.py b/pygmy/rest/shorturl.py index bab9f23..a9518a6 100644 --- a/pygmy/rest/shorturl.py +++ b/pygmy/rest/shorturl.py @@ -44,7 +44,7 @@ def post(self): if errors: log.error('Error in the request payload %s', errors) if errors.get('long_url'): - errors.update({'error': errors.get('long_url')}) + errors.update({'error': " ".join(errors.get('long_url'))}) return jsonify(errors), 400 long_url = data.pop('long_url') diff --git a/pygmyui/pygmy/views.py b/pygmyui/pygmy/views.py index e8adf59..7a966ab 100644 --- a/pygmyui/pygmy/views.py +++ b/pygmyui/pygmy/views.py @@ -61,12 +61,8 @@ def link_shortener(request): context=API_ERROR(e.args[0]), status=401) except (ObjectNotFound, InvalidInput) as e: - err = {} - err["error"] = (" ".join(API_ERROR(e.args[0])['error']) - if isinstance(API_ERROR(e.args[0])['error'],list) - else API_ERROR(e.args[0])['error']) return render(request, '400.html', - context=err, status=400) + context=API_ERROR(e.args[0]), status=400) short_code = resp['short_code'] else: return render( From 4a5af5b99ce420dd74be58900f8ea58cdfee1f56 Mon Sep 17 00:00:00 2001 From: hamid Date: Fri, 21 Jun 2019 22:54:36 +0400 Subject: [PATCH 3/4] Error message rendering changed --- pygmyui/restclient/error_msg.py | 6 +++--- pygmyui/templates/400.html | 4 +++- pygmyui/templates/404.html | 4 +++- pygmyui/templates/500.html | 6 ++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pygmyui/restclient/error_msg.py b/pygmyui/restclient/error_msg.py index ecae0d1..795c2c3 100644 --- a/pygmyui/restclient/error_msg.py +++ b/pygmyui/restclient/error_msg.py @@ -1,8 +1,8 @@ import json -INVALID_TOKEN = dict(error="Please log in again to continue.") -INTERNAL_SERVER_ERROR_API = "Something went wrong." +INVALID_TOKEN = dict(error=["Please log in again to continue."]) +INTERNAL_SERVER_ERROR_API = ["Something went wrong."] def API_ERROR(error_message): @@ -19,4 +19,4 @@ def API_ERROR(error_message): import traceback traceback.print_exc() error_message = INTERNAL_SERVER_ERROR_API - return dict(error=error_message) + return dict(error=error_message if isinstance(error_message,list) else [error_message]) diff --git a/pygmyui/templates/400.html b/pygmyui/templates/400.html index 8785517..07c8d94 100644 --- a/pygmyui/templates/400.html +++ b/pygmyui/templates/400.html @@ -3,7 +3,9 @@ {% block content %}

400


{% if error %} -

{{error}}

+ {%for err in error%} +

{{err}}

+ {%endfor%} {% else %}

Bad Request

{% endif %} diff --git a/pygmyui/templates/404.html b/pygmyui/templates/404.html index 3d39371..3e7aae7 100644 --- a/pygmyui/templates/404.html +++ b/pygmyui/templates/404.html @@ -3,7 +3,9 @@ {% block content %}

404


{% if error %} -

{{error}}

+ {%for err in error%} +

{{err}}

+ {%endfor%} {% else %}

Page Not Found

{% endif %} diff --git a/pygmyui/templates/500.html b/pygmyui/templates/500.html index 12291e3..65a48aa 100644 --- a/pygmyui/templates/500.html +++ b/pygmyui/templates/500.html @@ -3,8 +3,10 @@ {% block content %}

500


{% if error %} -

{{error}}

-{% else %} + {%for err in error%} +

{{err}}

+ {%endfor%} +{% else %}

Something Went Wrong

{% endif %} {% endblock content %} From d31372660bc8d1e6abeeb53236fd48c22f72bbcc Mon Sep 17 00:00:00 2001 From: hamid Date: Sat, 22 Jun 2019 19:44:47 +0400 Subject: [PATCH 4/4] Error message's rendering changed --- pygmy/rest/shorturl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmy/rest/shorturl.py b/pygmy/rest/shorturl.py index a9518a6..bab9f23 100644 --- a/pygmy/rest/shorturl.py +++ b/pygmy/rest/shorturl.py @@ -44,7 +44,7 @@ def post(self): if errors: log.error('Error in the request payload %s', errors) if errors.get('long_url'): - errors.update({'error': " ".join(errors.get('long_url'))}) + errors.update({'error': errors.get('long_url')}) return jsonify(errors), 400 long_url = data.pop('long_url')