Skip to content
Snippets Groups Projects
Verified Commit 4dd0f573 authored by Mark's avatar Mark
Browse files

Refactor Exception handling

parent f6384042
No related branches found
No related tags found
1 merge request!4Change consent provider backend to graphql
Pipeline #874 passed with stages
in 1 minute and 38 seconds
......@@ -2,8 +2,7 @@ from flask import abort, Flask, redirect, request
from flask.views import View
from os import urandom, environ
from hydra_client import HydraAdmin
from db import User
import urllib
from db import User, BackendConnectionError
HYDRA_ADMIN_URL = environ['HYDRA_ADMIN_URL']
......@@ -20,10 +19,10 @@ def home():
username = consent_request.subject
try:
user = User(username)
except urllib.error.HTTPError as e:
except BackendConnectionError as error:
# TODO: replace with propper logging via logger
print("Retrieving user object from GraphQL server failed")
print(e)
print(error)
return redirect(consent_request.reject(
"Permission denied",
error_description="Login request was denied due to an internal server error"))
......
......@@ -13,8 +13,11 @@ class User():
self.username = username
try:
self._load_remote_user_info()
except urllib.error.HTTPError as e:
raise e
except urllib.error.HTTPError as error:
raise BackendConnectionError(
error.code,
error.headers,
("Error during retrieval of userdata - " + error.reason))
def _load_remote_user_info(self):
querystring = '''{{
......@@ -57,3 +60,17 @@ class User():
"email" : self.email,
"picture": ""}
}
class BackendConnectionError(Exception):
"""Raised when requests to the backend server fail
Attributes:
code -- http response code
headers -- http response headers
reason -- reson for the error
"""
def __init__(self, code, headers, reason):
self.code = code
self.headers = headers
self.reaseon = reason
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment