-
-
Notifications
You must be signed in to change notification settings - Fork 389
Open
Description
Line 941 in 8b5ac00
handler(request=request, response=response, exception=exception, **kwargs) |
Line 910 in 8b5ac00
errors = self.validate(input_parameters, context) |
Line 273 in 8b5ac00
if key in input_parameters: |
Line 359 in 8b5ac00
def initialize_handler(handler, value, context): |
Line 363 in 8b5ac00
return handler(value) |
exception handler must trigger by bind exception raise
and the handler func args(exception) type hints is bind exception
initialize_handler
re-instantiate the custom Exception and pass in the first kwargs(exception), which is actually an instance of the custom Exception.Step 5 above is equivalent to --> CustomException(CustomException())
This is a contradiction and a serious error. Excuse me, what was the purpose of designing this initialize_handler function at that time?
reproduce:
# bug.py
import hug
import time
import hug.development_runner
class UserError(Exception):
code = 500
message = "Invalid username"
def __init__(self):
...
api = hug.API(__name__)
@hug.exception(UserError, api=api)
def handler_user_error(request, response, exception: UserError):
response.status = hug.falcon.HTTP_200
data = dict(data=None, msg=exception.message, timestamp=time.time(), code=exception.code)
response.body = hug.output_format.json(data)
route = hug.http(api=api)
@route.get("/test")
def get_data(**kwargs):
print("GET data")
raise UserError()
# run-bug-server.py
import hug.development_runner
hug.development_runner.hug("bug.py", port=5000)
curl --location --request GET 'localhost:5000/test'
{"errors": {"exception": "__init__() takes 1 positional argument but 2 were given"}}
{
"errors": {
"exception": "__init__() takes 1 positional argument but 2 were given"
}
}
Metadata
Metadata
Assignees
Labels
No labels