def server_error(e): code = 500 logging.error("Internal error [%s %s]: %s" % (request.method, request.url, e)) logging.exception(e) return json_response(HttpResponse(code=code, message="Internal error")), code
def api_response_handler(*args, **kwargs): try: response = f(*args, **kwargs) return response if response else json_response( HttpResponse()) except (BadRequest, InvalidInputException, InvalidValueException, PybootInvalidInputException, PybootInvalidValueException, PybootInvalidStateException) as e: logging.warning("Bad request [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=400, message=str(e))), 400 except (NotFoundException, PybootNotFoundException) as e: logging.warning("Not found [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=404, message=str(e))), 404 except (DuplicateValueException, PybootMultipleRowsFoundException, PybootDuplicateValueException) as e: logging.warning("Duplicate value: [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=409, message=str(e))), 409 except (AccessDeniedException, PybootAccessDeniedException, PybootAuthFailedException) as e: logging.warning("Access denied (Forbidden) [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=403, message=str(e))), 403 except UnauthorizedException as e: logging.warning("Unauthorized (Forbidden) [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=401, message=str(e))), 401 except MethodNotAllowedException as e: logging.warning("Method not allowed [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=405, message=str(e))), 405 except Exception as e: logging.error("Internal error [%s %s]: %s" % (request.method, request.url, e)) logging.exception(e) return json_response( HttpResponse(code=500, message="Internal error")), 500
def api_response_handler(*args, **kwargs): try: response = f(*args, **kwargs) return response if response else json_response(HttpResponse()) except (BadRequest, InvalidInputException, InvalidValueException) as e: logging.warning("Bad request [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=400, message=str(e))), 400 except NotFoundException as e: logging.warning("Not found [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=404, message=str(e))), 404 except DuplicateValueException as e: logging.warning("Duplicate value: [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=409, message=str(e))), 409 except AccessDeniedException as e: logging.warning("Access denied (Forbidden) [%s %s]: %s" % (request.method, request.url, e)) return json_response(HttpResponse(code=403, message=str(e))), 403 except Exception as e: logging.error("Internal error [%s %s]: %s" % (request.method, request.url, e)) logging.exception(e) return json_response(HttpResponse(code=500, message="Internal error")), 500
def sample_get(id): # Sample reding from config app_host = Conf.get("app_host") return json_response({"id": id, "app_host": app_host})
def sample_delete(id): return json_response({"id": id})
def sample_post(): json = request.get_json(force=True) return json_response(json)
def sample_put(id): json = request.get_json(force=True) if not json: json = {} json["id"] = id return json_response(json)
def update_message(id): dict = request.get_json(force=True) return json_response(MessageService().update_user_message_mapping( id, dict))
def save_to_drafts(): dict = request.get_json(force=True) return json_response(MailService().save_to_drafts(dict))
def get_placeholder_mails(id, placeholder_name): return json_response(UserService().get_placeholder_mails( id, placeholder_name))
def login(): dict = request.get_json(force=True) return json_response(UserService().login(dict))
def not_found(code): logging.info("Page not found [%s %s]: %s" % (request.method, request.url, code.code)) return json_response(HttpResponse(code=code.code, message="Not found")), code.code
def server_error(e): code = 500 logging.error("Internal error [%s %s]: %s" % (request.method, request.url, e)) logging.exception(e) return json_response(HttpResponse(code=code, message="Internal error")), code
def not_found(code): logging.info("Page not found [%s %s]: %s" % (request.method, request.url, code.code)) return json_response(HttpResponse(code=code.code, message="Not found")), code.code
def add_message(): dict = request.get_json(force=True) return json_response(MessageService().add(dict))
def forward_mail(): dict = request.get_json(force=True) return json_response(MailService().forward(dict))
def delete_mail(mapping_id): return json_response(MailService().delete(mapping_id))
def add_user(): dict = request.get_json(force=True) return json_response(UserService().add(dict))
def compose_mail(): dict = request.get_json(force=True) return json_response(MailService().compose(dict))
def get_message(id): include = ['user', 'parent', 'children'] return json_response(MessageService().get(id, include), include)