[Flask] abort(400, "my message") not returning 400

Daniel Watrous daniel.watrous at Trinet.com
Wed Dec 11 11:01:25 EST 2019


Callam,

Thanks for the reply. I did a little more sleuthing and found that I was catching Exception in a wrapper that ensured a user was logged in. When I caught that, I threw an abort 500. When I read the documentation closer, I noticed that abort throws and HTTPExecption, so I was effectively catching that and ‘changing’ the abort to a 500.

I removed that global Exception catch and now abort is working as expected.

Daniel

From: "Cal97g ." <cal.97g at gmail.com>
Date: Tuesday, December 10, 2019 at 4:33 PM
To: Daniel Watrous <daniel.watrous at Trinet.com>
Cc: "flask at python.org" <flask at python.org>
Subject: Re: [Flask] abort(400, "my message") not returning 400

Can we see where your application is initialised? Have you configured any error handlers?

Many Thanks
Callam Delaney


On Tue, 10 Dec 2019 at 21:23, Daniel Watrous <daniel.watrous at trinet.com<mailto:daniel.watrous at trinet.com>> wrote:
Hi,

I have the following line in my flask application
            abort(400, "failure, User %s not found" % participant)

When that line is executed, I get a 500 reponse, not 400. I do get the error message, but he response is embedded in HTML.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>Error: 400 Bad Request: failure, User notauser not found</p>

Based on the docs, I expected to get a 400 error and a non-HTML response with just he message. Is there some way to achieve this?

Thanks,
Daniel

_______________________________________________
Flask mailing list
Flask at python.org<mailto:Flask at python.org>
https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20191211/2fead461/attachment-0001.html>


More information about the Flask mailing list