Skip to content

Commit

Permalink
Fix #5, correct error messages from API, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
amitt001 committed Dec 9, 2017
1 parent d10ac90 commit a2d2a2d
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 30 deletions.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cffi==1.11.2
chardet==3.0.4
click==6.7
decorator==4.1.2
Django==1.11.7
Django==2.0
Flask==0.12.2
Flask-Cors==3.0.3
Flask-JWT-Extended==3.3.4
Expand All @@ -30,7 +30,7 @@ ptyprocess==0.5.2
pycparser==2.18
Pygments==2.2.0
PyJWT==1.5.3
pytest==3.2.5
pytest==3.3.1
pytz==2017.3
requests==2.18.4
simplegeneric==0.8.1
Expand All @@ -39,4 +39,4 @@ SQLAlchemy==1.1.15
traitlets==4.3.2
urllib3==1.22
wcwidth==0.1.7
Werkzeug==0.12.2
Werkzeug==0.13
10 changes: 5 additions & 5 deletions src/pygmy/rest/shorturl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get(self):
return jsonify(dict(error='Invalid URL.')), 400
link = self.manager.get(long_url)
if self.manager.has_expired():
return jsonify(dict(message="Link has expired")), 404
return jsonify(dict(error="Link has expired")), 404
if link is None:
abort(404)
result = self.schema.dump(link)
Expand Down Expand Up @@ -74,11 +74,11 @@ def get(self):
query_by_code=True, request=request)
result = self.schema.dump(long_url)
except LinkExpired:
return jsonify(dict(message="Link has expired")), 410
return jsonify(dict(error="Link has expired")), 410
except URLAuthFailed:
return jsonify(dict(message="Secret key not provided")), 403
return jsonify(dict(error="Secret key not provided")), 403
except URLNotFound:
return jsonify(dict(message="Invalid/Expired url")), 404
return jsonify(dict(error="Invalid/Expired URL")), 404
return jsonify(result.data), 200


Expand All @@ -102,7 +102,7 @@ def resolve(code):
code.strip('+'), request=request, secret_key=secret_key)
response = redirect(long_url, code=301)
except LinkExpired:
response = jsonify(dict(message="Link has expired")), 404
response = jsonify(dict(error="Link has expired")), 404
except URLAuthFailed:
response = jsonify({'error': 'Access to URL forbidden'}), 403
except (URLNotFound, AssertionError):
Expand Down
2 changes: 1 addition & 1 deletion src/pygmy/rest/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get(self, user_id=None):
params['email'] = request.args.get('email')
user = UserManager().find(**params)
if user is None:
return jsonify(dict(message="User not found")), 404
return jsonify(dict(error="User not found")), 404
result = self.schema.dump(user)
return jsonify(result.data), 200

Expand Down
6 changes: 0 additions & 6 deletions src/pyui/pygmy/admin.py

This file was deleted.

Empty file.
10 changes: 3 additions & 7 deletions src/pyui/pygmy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def link_unshorten(request, code):
url_obj = pygmy_client.unshorten(code)
except UnAuthorized:
return redirect('/link/secret?next={}'.format(code))
except LinkExpired:
return render(request, '404.html', status=404)
except ObjectNotFound as e:
except (LinkExpired, ObjectNotFound) as e:
return render(request, '404.html',
context=API_ERROR(e.args[0]), status=404)
long_url = url_obj['long_url']
Expand Down Expand Up @@ -136,9 +134,7 @@ def short_link_stats(request, code):
context=API_ERROR(dict(
error='Secret link stats are not yet supported.')
), status=404)
except LinkExpired:
return render(request, '404.html', status=404)
except ObjectNotFound as e:
except (ObjectNotFound, LinkExpired) as e:
return render(request, '404.html',
context=API_ERROR(e.args[0]), status=404)
return render(request, 'pygmy/link_stats.html', context=context)
Expand Down Expand Up @@ -168,7 +164,7 @@ def link_auth(request):
url_obj = pygmy_client.unshorten(code, secret_key=secret_key)
response = dict(long_url=url_obj['long_url'])
except UnAuthorized:
response = dict(message='Wrong secret key.')
response = dict(error='Wrong secret key.')
except ObjectNotFound as e:
return render(
request, '404.html', context=API_ERROR(e.args[0]), status=404)
Expand Down
2 changes: 0 additions & 2 deletions src/pyui/pyui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin
import pyui.generic_views as views


urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^favicon.ico', views.dummy),
url(r'^about', views.about),
url(r'^contact', views.contact),
Expand Down
6 changes: 0 additions & 6 deletions src/pyui/user_auth/admin.py

This file was deleted.

Empty file.

0 comments on commit a2d2a2d

Please sign in to comment.