def type_error(error_instance): error("type_error") exception(error_instance) message = str(error_instance).replace("__init__() ", "") code = 400 title = 'Bad request' return fault(message, STORAGE_0012, code, title)
def bad_request(exception_instance): error("bad_request") exception(exception_instance) message = exception_instance.description code = 400 title = 'Bad request' return fault(message, STORAGE_0004, code, title)
def value_error(error_instance): error("value_error") exception(error_instance) message = str(error_instance) code = 400 title = 'Bad request' return fault(message, STORAGE_0011, code, title)
def connexion_bad_request(exception_instance): error("connexion_bad_request") exception(exception_instance) message = exception_instance.detail code = exception_instance.status title = exception_instance.title return fault(message, STORAGE_9999, code, title)
def storage_bad_request(exception_instance): error("storage_bad_request") exception(exception_instance) message = exception_instance.description code = 409 title = 'Bad request' return fault(message, exception_instance.error_code, code, title)
def internal_server_error(error_instance): error("internal_server_error") exception(error_instance) message = str(error_instance) code = 500 if isinstance(error_instance, HTTPException): code = error_instance.code title = 'Internal server error' return fault(message, STORAGE_0001, code, title)
def integrity_error(error_instance): error("integrity_error") exception(error_instance) if "unique constraint" in str(error_instance): message = "Unique constraint: please check request values on uniquiness" else: message = str(error_instance) code = 400 title = 'Bad request' return fault(message, STORAGE_0014, code, title)
def func_wrapper(*args, **kwargs): verified = verify_auth_token(request_parameters().get('token'), get_ip(), security_path(path), operation) if not verified: response = fault(PERMISSION_DENIED, STORAGE_0000, 419, PERMISSION_DENIED) else: response = func(*args, **kwargs) return response
def invalid_request_error(error_instance): error("invalid_request_error") exception(error_instance) message = str(error_instance) \ .replace("'", "") \ .replace("class ", "") \ .replace("app.classes.", "") \ .replace("<", "") \ .replace(">", "") code = 400 title = 'Bad request' return fault(message, STORAGE_0013, code, title)
def delete_entity(clazz, entity_id, token): entity_name = clazz.__name__ instance = '/' + entity_name.lower() + '/' + str(entity_id) if entity_name in SENSITIVE_DATA_CLASSES: json, code = delete_private_response() if code != 200: return make_json_response(json, code) with session_scope() as session: entity_db = session.query(clazz).filter_by(id=uuid.UUID(entity_id)) if entity_db.first() is None: response = fault(entity_name + ' not found', STORAGE_0003, 404, RESOURCE_NOT_FOUND, REST_GUIDE + entity_name + 's', instance, 'delete') else: entity_db.delete() response = success( 'DELETE /' + entity_name.lower() + '/' + entity_id, 200, 'Success', REST_GUIDE + entity_name + 's', instance, 'delete') return response
def handle_forbidden(exception_instance): error("handle_forbidden") message = exception_instance.description return fault(message, STORAGE_0009, 403, PERMISSION_DENIED)
def unhandled_exception(exception_instance): error("unhandled_exception") exception(exception_instance) message = str(exception_instance) return fault(message, STORAGE_0002, 404, RESOURCE_NOT_FOUND)