Connexion视图函数抛出500错误而不是捕获异常

问题描述

因此,我具有以下视图功能(我正在尝试在Open APIV3项目上工作):

def my_view_func_in_python():
    return_dict = {"status": False,"stdout": None,"stderr": None}
    try:
        payload = connexion.request.get_json()
        json_data = payload["json"]
        fileName = payload["fileName"]
        text_lines = []

        for line in json_data["res"][0]["lines"]:
            text_lines.append(line["text"])

        text = " ".join(text_lines)
        os.remove("./assets/request.jpg")

        return_dict.update([
            ("status",True)
        ])

    except BaseException as ex:
        return_dict.update([
            ("stderr",ex)
        ])

    return return_dict

现在由于某种原因,如果我通过挥舞给出一个空的json字段值,则代码会在具有for循环for line in json_data["res"][0]["lines"]的行中中断。但是,如果它中断了,它应该进入例外行并和平返回return_dict。但是它给我的回报是挥舞着500错误

SWAGGER输出

{
  "detail": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.","status": 500,"title": "Internal Server Error","type": "about:blank"
}

,在我托管应用程序的后端发生什么错误

TypeError: Object of type 'KeyError' is not JSON serializable

我已经尝试了很多地方,开放的apiv3规范,swagger文档和connexion文档。我不能只捕捉到此错误!我该怎么办?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...