【发布时间】:2015-08-26 10:56:46
【问题描述】:
我有一个用 pyramid_rpc 编写的应用程序。我们通过 json_rpc 在网络上调用我们的函数。有时用户输入中有错误(逻辑错误),我想向用户返回自定义错误。例如考虑这部分代码:
@jsonrpc_method(method='calc.insurance.fee', endpoint="api")
def market_engine_beta(request, person_id: int, age: int):
if age < 10:
raise ValueError('age should be bigger than 10')
但是当我使用 age=8 调用该方法时,我看到了这个错误: {“jsonrpc”:“2.0”,“id”:“1”,“错误”:{“消息”:“内部错误”,“代码”:-32603}}
如何将我的错误返回给用户? 笔记: 我也试过这个链接:http://docs.pylonsproject.org/projects/pyramid//en/latest/narr/views.html#custom-exception-views
【问题讨论】:
标签: python python-3.x pyramid json-rpc