mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-10-30 17:47:50 +00:00
- add POST, PUT, DELETE on equipments - add POST, PUT, GET, DELETE on topogies - path-computation request body can now have equipment id and/or topology id instead of full data - activate embedded https of Flask while waiting for real trusted certificate - update readme - add request payload samples in yang directory - equipment data are encrypted with Fernet Signed-off-by: manuedelf <59697943+edelfour@users.noreply.github.com>
34 lines
994 B
Python
34 lines
994 B
Python
# coding: utf-8
|
|
import json
|
|
import re
|
|
|
|
import werkzeug
|
|
|
|
from gnpy.api.model.error import Error
|
|
|
|
_reaesc = re.compile(r'\x1b[^m]*m')
|
|
|
|
|
|
def common_error_handler(exception):
|
|
"""
|
|
|
|
:type exception: Exception
|
|
|
|
"""
|
|
status_code = 500
|
|
if not isinstance(exception, werkzeug.exceptions.HTTPException):
|
|
exception = werkzeug.exceptions.InternalServerError()
|
|
exception.description = "Something went wrong on our side."
|
|
else:
|
|
status_code = exception.code
|
|
response = Error(message=exception.name, description=exception.description,
|
|
code=status_code)
|
|
|
|
return werkzeug.Response(response=json.dumps(response.__dict__), status=status_code, mimetype='application/json')
|
|
|
|
|
|
def bad_request_handler(exception):
|
|
response = Error(message='bad request', description=_reaesc.sub('', str(exception)),
|
|
code=400)
|
|
return werkzeug.Response(response=json.dumps(response.__dict__), status=400, mimetype='application/json')
|