def make_error(self, error: HTTPException) -> dict: """make a flask valid error response""" resp = jsonify(self.__dict__) resp.status_code = self.get_status_code() error.description = self.description resp.error = error return resp
def handle_404( e: HTTPException ) -> Union[Tuple[str, int], werkzeug.wrappers.Response]: # Switch out the default message if e.description == werkzeug.exceptions.NotFound.description: e.description = "Requested page not found. Looks like this was deleted, or maybe was never here." if request.path.startswith("/api/") \ or (request.accept_mimetypes.accept_json and not request.accept_mimetypes.accept_html): return jsonify_exception(e) return render_template("error_404.html", error=e), 404
def E400(desc, code=400): """ 未知错误处理,并抛出到 error_handling 中 :param desc: 错误信息 :param code: 错误编码 默认 400 :return: """ exc = HTTPException() if isinstance(code, enum.Enum): exc.status_code = code.value else: exc.status_code = code exc.description = desc return error_handling(exc)
def _400(desc): # pragma: no cover exc = HTTPException() exc.code = 400 exc.description = desc return error_handling(exc)
def _400(desc): exc = HTTPException() exc.code = 400 exc.description = desc return error_handling(exc)
def error(error_code): exception = HTTPException() exception.description = errors[error_code] exception.code = error_code return exception