金字塔忽略自定义异常

2024-09-26 22:11:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我想我可能在使用金字塔和处理自定义错误代码/异常时遇到问题

在后端应用程序中,我提出了一个errareCatalog.errExtapiFulfillIdDeprecated当一个特定的事件发生时,我不认为这是有意义的,但下面是我在errareCatalog.py中提出的:

class errExtapiFulfillIdDeprecated(errare.processingErrare):
  e_mnemonic = 'ERR_FULFILL_ID_DEPRECATED'
  e_baseMsg = gettext('Fulfill id is deprecated')
  e_errCatalogNumber = -21008

我试图通过以下方式在前端部分捕获此异常:

from pyramid.httpexceptions import HTTPNotFound
from hll.errors import errareCatalog

try :
  stuff that raise and exception
except errareCatalog.errExtapiFulfillIdDeprecated as ex :
  request.response.status_code = 404
  print 'throwin 404'
  return HTTPNotFound()  

问题是,我似乎从来没有参与过这个,除了。在某个地方抛出了一个500错误,并将我重定向到500页。 我是不是在提升/捕获异常的方式上做错了什么,或者金字塔中缺少了配置?你知道吗

编辑:这是我的异常视图

@view_config(context=errareCatalog.errExtapiFulfillIdDeprecated, permission=NO_PERMISSION_REQUIRED)
def mobile_ticket_error(exc, request):
  print 'test error'
  logger.exception("DEPRECATED FULFILLID: %s" % str(exc))   
  return render_to_response("mylogin:templates/mobile-ticket-error.genshi",
                            {'message': str(exc),
                            'layout_name': get_layout_name(request)},
                            request=request)  

Tags: fromimportreturnresponserequest方式exceptionerror

热门问题