1
0
Files
synapse/synapse_topology/controller/server/error_handlers.py
2019-08-28 15:59:53 +01:00

47 lines
1.3 KiB
Python

from jsonschema import ValidationError
from simplejson.errors import JSONDecodeError
from synapse_topology.model.errors import (
BasConfigInUseError,
BaseConfigNotFoundError,
ConfigNotFoundError,
)
from . import app
@app.handle_errors(ValidationError)
def validation_error(request, failure):
request.setResponseCode(400)
print("Invalid post schema {}".format(failure.getErrorMessage()))
return "Invalid post schema {}".format(failure.getErrorMessage())
@app.handle_errors(JSONDecodeError)
def json_decode_error(request, failure):
request.setResponseCode(400)
return "Invalid post json"
@app.handle_errors(BaseConfigNotFoundError)
def base_config_not_found(request, failure):
request.setResponseCode(500)
return "Config file not setup, please initialise it using the /servername endpoint"
@app.handle_errors(ConfigNotFoundError)
def config_not_found(request, failure):
request.setResponseCode(404)
return "The config does not exist"
@app.handle_errors(BasConfigInUseError)
def base_config_in_use(request, failure):
request.setResponseCode(409)
return "Sever name and keys already configured"
@app.handle_errors(Exception)
def handle_generic_error(request, failure):
request.setResponseCode(500)
return "Internal server error\n{}".format(failure)