MR comments

- added error handler for unauthorized
This commit is contained in:
Davor 2022-06-09 12:21:47 +02:00
parent 907e0ecaab
commit 19bc31e6e3
4 changed files with 12 additions and 2 deletions

View file

@ -1,10 +1,10 @@
from functools import wraps
from flask import jsonify
from areas.roles.role_service import RoleService
from flask_jwt_extended import verify_jwt_in_request
from flask_jwt_extended import get_jwt
from helpers import Unauthorized
def admin_required():
def wrapper(fn):
@ -17,7 +17,7 @@ def admin_required():
if isAdmin:
return fn(*args, **kwargs)
else:
return jsonify(msg="Admins only!"), 403
raise Unauthorized("You need to have admin permissions.")
return decorator

View file

@ -13,6 +13,8 @@ class HydraError(Exception):
class BadRequest(Exception):
pass
class Unauthorized(Exception):
pass
def bad_request_error(e):
message = e.args[0] if e.args else "Bad request to the server."
@ -42,3 +44,7 @@ def hydra_error(e):
def global_error(e):
message = str(e)
return jsonify({"errorMessage": message}), 500
def unauthorized_error(e):
message = str(e)
return jsonify({"errorMessaeg": message}), 403