A customer wants a specific error code when certain apis fail to load. I am thinking of blocking the URL where apis come from.

  • I was given the task to verify our developers have implemented the right error code as per our customers request.

I have tried to redirect the URL to localhost in my hosts file (I am using a MacBook), but it did not work.

closed as off-topic by Amias, Niels van Reijmersdal, NarendraC, Bharat Mane, Nitin Rastogi Aug 14 at 12:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software engineering unrelated to testing are off-topic here, but can be asked on Programmers Stack Exchange." – Amias, Niels van Reijmersdal, NarendraC, Bharat Mane, Nitin Rastogi
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    I have voted to close this as offtopic since this has nothing to do with Quality Assurance. However even if you will post your question somewhere else I would recommend to add more details like what you mean under load api from url? Since noramlly one does not load API from URL but calls a function of API via URL. So in your question it is worth improving the problem statement. What are you trying to achieve. – Alexey R. Aug 10 at 9:12
  • @AlexeyR., thanks, I have added my reason to ask this question on QA. – oscar Aug 10 at 19:45
up vote 2 down vote accepted

You can use Fiddler as a proxy that will let you filter and change your web requests. I'm not familiar with exactly how it is on a Mac, but on a PC, you can edit the FiddlerScript and they have an example on how to break specific requests:

// Sample Rule: Break requests for URLs containing "/sandbox/"
if (oSession.uriContains("/sandbox/")) {
    oSession.oFlags["x-breakrequest"] = "yup";  // Existence of the x-breakrequest flag creates a breakpoint; the "yup" value is unimportant.
}

That should be enough of a starting point to get you to mung the request and response however you want to.

Have you tried using a browser extension instead?

With switcheroo, basically, you will need to:

  1. Enable this extension
  2. Go to the developer tool -> Network tab, look for the URL (you are more likely already know which URL you need)
  3. Copy and paste this URL into switcheroo, and redirect it to a silly / random URL.
  4. APIs should fail to load

If you're on a Mac you can also check out Charles Proxy. It is a robust proxy tool that allows you to monitor an manipulate traffic on your mac as well as other devices (such as mobile or set-top devices) on your network.

Look at this answer for specifics on rewriting a response with a specific status code:

https://stackoverflow.com/a/18667949/2588811

Not the answer you're looking for? Browse other questions tagged or ask your own question.