Search code examples
pythonrestnginxpostmanhttp-status-code-400

How to intentionally cause a 400 Bad Request in Nginx?


I've split my previous question into two.

A consumer of my REST API says that on occasion I am returning a 400 Bad Request - The request sent by the client was syntactically incorrect. error.

My application (Python/Flask) logs don't seem to be capturing this, and neither do my webserver/Nginx logs.

I've changed the default 400 and 404 error message HTML's by adding the following line to the config (and adding the corresponding HTML pages in the proper directory):

    error_page  404              /404.html;
    location = /404.html {
        root   html;
    }
    error_page  400              /400.html;
    location = /400.html {
        root   html;
    }

This error message plainly states "Nginx" so that I know Nginx is giving the 400 and not my python/flask application (whose 400 has been changed to plainly state "Flask").

Is there a way that I can intentionally cause Nginx to return a 400 error, perhaps through python, CURL, or Postman? For example, I've also changed the 404 error page, and can intentionally get Nginx to return the corresponding error HTML by calling an invalid URL.


Solution

  • Create a location in NGINX's config to return 400 errors:

    location /error { 
        return 400;
    }
    

    Presto.