2021年2月4日星期四

raise exception as http response

I'm using django and vue to write a Programmer. Could I raise an exception as a http response, so I can raise the exception anywhere, and do not need to catch it in the django view function, and then reassemble it into a new http response.

Pseudocode

try:    a = ['0']    b = a[2]  except IndexError as e:    raise ExceptionAsHttpResponse(status=404, reason='haha')  # Not implemented, hope to get your help.  

after the raise ExceptionAsHttpResponse, the frontend can just accquire the status and reason

https://stackoverflow.com/questions/66057452/raise-exception-as-http-response February 05, 2021 at 12:08PM

没有评论:

发表评论