I'm writing a simple REST service with Flask. When an exception occurs in my code, I get a nice error message and an interactive debugger in my browser. However, if I call the service from the command line (e.g. with curl), or in my unit tests, and something fails, I still get the formatted (HTML) error message. I remember that I sometimes got a plain text message instead (basically just the Python error + traceback), and I don't know how Flask decides to serve plain text or HTML.
How do I make it so that Flask returns plain (non-interactive, non-HTML) error messages when accessed without a browser?