hugapi / hug

Embrace the APIs of the future. Hug aims to make developing APIs as simple as possible, but no simpler.
MIT License
6.86k stars 388 forks source link

Exception handler: Why find a potential handler doesn't exit the loop #911

Open Panlq opened 1 year ago

Panlq commented 1 year ago

https://github.com/hugapi/hug/blob/8b5ac00632543addfdcecc326d0475a685a0cba7/hug/interface.py#L936

  1. Why find a potential handler doesn't exit the loop?
  2. https://github.com/hugapi/hug/blob/8b5ac00632543addfdcecc326d0475a685a0cba7/hug/interface.py#L935

potential_handler The handler may just be a function that does not call hug.exception(SomeException, potential_handler) injects the handle And it is directly called http.add_exception_handler method to inject an exception handler This situation results in an AttributeError

  File "/root/.cache/pypoetry/virtualenvs/xxxx-CoXUkZCy-py3.8/lib/python3.8/site-packages/hug/interface.py", line 919, in __call__
    if not isinstance(exception, potential_handler.exclude):
AttributeError: 'function' object has no attribute 'exclude'

Whether it is necessary to increase robustness? like:

if hasattr(potential_handler, "exclude") and isinstance(exception, potential_handler.exclude):
   continue