dashboard/helpers/kratos_api.py

56 lines
1.4 KiB
Python
Raw Normal View History

from logging import error
2021-10-28 16:09:10 +02:00
import requests
from config import *
from .error_handler import KratosError
class KratosApi:
@staticmethod
def __handleError(res):
if res.status_code >= 400:
message = res.json()["error"]["message"]
raise KratosError(message, res.status_code)
2021-10-28 16:09:10 +02:00
@staticmethod
def get(url):
try:
res = requests.get("{}{}".format(KRATOS_URL, url))
KratosApi.__handleError(res)
return res
2021-10-28 16:09:10 +02:00
except:
raise KratosError()
2021-10-28 16:09:10 +02:00
@staticmethod
def post(url, data):
try:
res = requests.post("{}{}".format(KRATOS_URL, url), json=data)
KratosApi.__handleError(res)
return res
except KratosError as err:
raise err
2021-10-28 16:09:10 +02:00
except:
raise KratosError()
2021-10-28 16:09:10 +02:00
@staticmethod
def put(url, data):
try:
res = requests.put("{}{}".format(KRATOS_URL, url), json=data)
KratosApi.__handleError(res)
return res
except KratosError as err:
raise err
2021-10-28 16:09:10 +02:00
except:
raise KratosError()
2021-10-28 16:09:10 +02:00
@staticmethod
def delete(url):
try:
res = requests.delete("{}{}".format(KRATOS_URL, url))
KratosApi.__handleError(res)
return res
except KratosError as err:
raise err
2021-10-28 16:09:10 +02:00
except:
raise KratosError()