def handle_500(e): """ 处理业务代码异常页面 :param e: :return: """ exc_type, exc_value, exc_tb = sys.exc_info() tc = traceback.format_tb(exc_tb) if properties.debug_trace: trace_detail = '<h4>Details</h4>' trace_detail += '<table style="width:100%;" cellspacing="0" cellpadding="4">' for tc_item in tc: if tc_item.find(os.getcwd()) < 0: continue trace_detail += '<tr>' tc_item_info_list = tc_item.split(',', 2) # for tc_item_info_list_item in tc_item_info_list: # trace_detail += '<td>' + tc_item_info_list_item + '</td>' trace_detail += '<td style="border: 1px solid gray;">' + re.sub( '(^.+(\\\|/))|"', '', tc_item_info_list[0]) + '</td>' trace_detail += '<td style="border: 1px solid gray;">' + tc_item_info_list[ 1] + '</td>' trace_code_detail = re.sub('^\s+', '', tc_item_info_list[2]).split(' ', 1) trace_detail += '<td style="border: 1px solid gray;">' + ' => '.join( [ trace_code_detail[0], re.sub('\s+', ' => ', trace_code_detail[1], 1), ]) + '</td>' trace_detail += '<tr>' trace_detail += '</table>' else: trace_detail = '' if error_info == error_info_type.HTML: return '<h1>Wrong!!</h1>' + \ '<h2>error info:' + str(e) + '</h2>' + \ '<h3>please contact coder or direct to ' \ '<a href="https://dophon.blog">dophon</a> and leave your question</h3>' + \ trace_detail, 500 elif error_info == error_info_type.JSON: return self_result.JsonResult( 500, tc, """ please contact coder or direct to dophon website and leave your question """).as_res() elif error_info == error_info_type.XML: return self_result.XmlResult( 500, tc, """ please contact coder or direct to dophon website and leave your question """).as_res()
def handle_404(e): """ 处理路径匹配异常 :return: """ global error_info if error_info == error_info_type.HTML: return '<h1>Wrong!!</h1>' + \ '<h2>error info:' + str(e) + '</h2>' + \ '<h3>please contact coder or direct to ' \ '<a href="https://dophon.blog">dophon</a> and leave your question</h3>' + \ 'request path:' + request.path, 404 elif error_info == error_info_type.JSON: return self_result.JsonResult(404, request.path, 'please check your path').as_res() elif error_info == error_info_type.XML: return self_result.XmlResult(404, request.path, 'please check your path').as_res()
def handle_405(e): """ 处理请求方法异常 :return: """ if error_info == error_info_type.HTML: return '<h1>Wrong!!</h1>' + \ '<h2>error info:' + str(e) + '</h2>' + \ '<h3>please contact coder or direct to ' \ '<a href="https://dophon.blog">dophon</a> and leave your question</h3>' + \ 'request method:' + request.method, 405 elif error_info == error_info_type.JSON: return self_result.JsonResult( 405, {request.path, request.method}, 'please check your request method').as_res() elif error_info == error_info_type.XML: return self_result.XmlResult( 405, {request.path, request.method}, 'please check your request method').as_res()
def handle_400(e): """ 处理异常请求 :return: """ if error_info == error_info_type.HTML: return ('<h1>Wrong!!</h1>' + \ '<h2>error info:' + str(e) + '</h2>' + \ '<h3>please contact coder or direct to ' '<a href="https://dophon.blog">dophon</a> and leave your question</h3>' + \ 'request form:' + request.form + \ 'request body:' + request.json if request.is_json else ''), 400 elif error_info == error_info_type.JSON: return self_result.JsonResult( 400, request.json if request.is_json else '', 'please check your request data').as_res() elif error_info == error_info_type.XML: return self_result.XmlResult( 400, request.json if request.is_json else '', 'please check your request data').as_res()