Robyn icon indicating copy to clipboard operation
Robyn copied to clipboard

If i raise a exceptions and Robyn will not handle them

Open T-baby opened this issue 2 years ago • 2 comments

Bug Description

I tried to add a handle_exception as per the documentation, but nothing worked.

Steps to Reproduce

@app.exception
def handle_exception(error):
    return {"status_code": 500, "body": f"error msg: {error}"}

@app.get("/")
async def hello(request):
    raise BaseException("BaseException")
    return jsonify({"message": "Hello World"})

If I send a request to this URL directly, I just get "Internal server error".

Your operating system

MacOS

Your Python version (python --version)

3.11

Your Robyn version

latest

Additional Info

No response

T-baby avatar Jul 28 '23 09:07 T-baby

Hey @T-baby 👋

Thank you for raising an issue. But there is an issue with the code. You should never raise a BaseException, as it serves as the base class for all the other exceptions. You should raise an Exception or better a specific exception in your code. I hope this helps 😄

Let me know if you have any more questions 😄

sansyrox avatar Jul 29 '23 14:07 sansyrox

How can we handle 404 status when a route is not defined?I tried to use after_request interception is feasible, is there any other better solution?

T-baby avatar Jul 30 '23 05:07 T-baby