Overriding Default Werkzeug Exceptions in Flask

Update 15.06.2018:The issue described in this post is now a history,
read the epic story of my
struggle to get it fixed.

Let’s play a game here. What HTTP code is this exception:

{"message":"The browser (or proxy) sent a request that this server could not understand."}

No no, you don’t look at the code in response! That’s cheating! This is
actually a default Werkzeug description for 400 code. No shit. I thought
something is bad with my headers or encryption, but I would never guess simple
Bad request from this message. You could use a custom exception of course,
the problem is, that the very useful abort(400) object (it’s an Aborter in
disguise) would stick with the default exception anyway. Let’s fix it, shall we?

There may be several possible ways of fixing that, but what I’m gonna do is
just update abort.mapping. Create a separate module for your custom HTTP
exceptions custom_http_exceptions.py and put a couple of overridden
exceptions there (don’t forget to import abort we’ll be needing that in a
moment):