Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing an HTTP request to fail in browser

Tags:

Is it possible to make an http request that has been sent to a server by the browser fail without having to alter the javascript?

I have a POST request that my website is sending to the server and we are trying to test how our code reacts when the request fails (e.g. an HTTP 500 response). Unfortunately, the environment that I need to test it in has uglified and compressed javascript, so inserting a breakpoint or altering the javascript isn't an option. Is there a way for us to utilize any browser to simulate a failed request?

The request takes a long time to complete, so using the browser's console to run a javascript command is a possibility.

I have tried using window.stop(), however, this does not work since I need to failure code to execute.

I am aware of the option of setting up a proxy server, but would like to avoid this is possible.

like image 602
Peter Maidens Avatar asked Oct 20 '14 18:10

Peter Maidens


People also ask

How do you fail HTTP request?

In Chrome (just checked v63), you can actually block a specific URL (or even a whole domain) from the Network tab. You only need to right-click on the entry and select Block request URL (or Block request domain .) Show activity on this post. Show activity on this post.

How do you fail an API?

Here are some rule of thumb: Use 500 for server unexpected errors, reserving 503 for planned service unavailability. Reserve the 502 and 504 codes for reverse proxies. A failure when contacting an internal third-party system should still use a 500 when this internal system is not visible to the client.

How do I know if browser request is coming?

There is absolutely no way to know with certainty if a request came from a browser or something else making an HTTP request. The HTTP protocol allows for the client to set the User Agent arbitrarily.


1 Answers

In Chrome (just checked v63), you can actually block a specific URL (or even a whole domain) from the Network tab. You only need to right-click on the entry and select Block request URL (or Block request domain.)

like image 194
davguij Avatar answered Oct 08 '22 07:10

davguij