aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/base_route.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-02-09 12:51:58 +0000
committerGravatar Gareth Coles <[email protected]>2018-02-09 12:51:58 +0000
commitf18a4dede529d3bf2ed524d2e0efcdb9e8419d58 (patch)
treea51530fa54bbf15f2559659db8469669dbfb3ad2 /pysite/base_route.py
parentMove from straight app registration to Blueprints (#6) (diff)
Base API route and error codes enum
Diffstat (limited to 'pysite/base_route.py')
-rw-r--r--pysite/base_route.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py
index 8274e66f..0306e724 100644
--- a/pysite/base_route.py
+++ b/pysite/base_route.py
@@ -1,7 +1,9 @@
# coding=utf-8
-from flask import Blueprint, render_template
+from flask import Blueprint, render_template, jsonify
from flask.views import MethodView
+from pysite.constants import ErrorCodes
+
class BaseView(MethodView):
name = None # type: str
@@ -24,6 +26,19 @@ class RouteView(BaseView):
blueprint.add_url_rule(cls.path, view_func=cls.as_view(cls.name))
+class APIView(BaseView):
+ def error(self, error_code: ErrorCodes):
+ data = {
+ "error_code": error_code.value,
+ "error_message": "Unknown error"
+ }
+
+ if error_code is ErrorCodes.unknown_route:
+ data["error_message"] = "Unknown API route"
+
+ return jsonify(data)
+
+
class ErrorView(BaseView):
error_code = None # type: int