visit
Writing code that works when everything functions as expected can be termed as Happy Path Coding. It is a desirable state but this does not happen as often as expected. An experienced developer thinks of all possible use cases and corner cases and makes sure his code informs the users of an application if an unexpected error happens. This level of coding is brilliant and the best way to operate in Software Engineering.
But sometimes developers tend to forget to consider users when rushing to meet deadlines or if they are inexperienced and ignore their coding for errors.Let’s say you are building a Web Application that will fetch a list of products that users can browse and pick. For this, the web application might be calling a REST Endpoint to fetch the list of products(Eg:- GET //yourbackendapi/products).
Typically, developers will expect that the REST Endpoint will always respond with SUCCESS response (200 ok) and ignore error scenarios like 401(Unauthorised Exception), 500 (Internal Server Error), 502 (Bad Gateway), etc.When a web application does not give an informed response to a customer and pushes the app to an "unknown state or view", you finally end up with an unhappy customer
Displaying a message such as - “Looks like we are running into an issue. Please contact Tech Support @ [email protected] if the problem persists” delivers a better user experience and is far preferable to displaying an exception message that says something like “Unexpected end of JSON input at 0”.
How can the QA team identify these types of errors and find badly handled error scenarios?
The first tool that I would like to recommend is , a browser extension that enables to intercept all the API calls passing through the browser. Once intercepted, it can then redirect the API call or modify the request/response headers.
Using Requestly and Mockoon , to test the underlying API call (in our example above (GET can be intercepted and redirected to a mock API which is built using Mockoon.
The mock API can then be configured to respond with 4xx or 5xx errors to see how your web application handles these API errors.Hence, this test will enable the QA team to identify whether the web application is gracefully handling the errors, providing users with informative messages rather than throwing technical jargon responses.Architecture Design for Error Handling Testing
Here is a step-by-step flow to the configuration :
1. Identify the use case and API that’s being called to display the data in the user interface. In our example, it is “//yourbackendapi/products”.
2. Create a mock API using Mockoon to respond with 500.Check how the User Interface is responding to different errors. If API responds with a 500 message, the user interface should respond with a message like “Something went wrong. Please contact [email protected] if the problem persists rather than an ugly tech-riddled message.
Troubleshooting tips:
- Make sure HTTPS is enabled on the mockAPI if your web application is on HTTPS. - Make sure CORS is enabled if you observe any CORS errors.Let me know! Reach out on my socials with your comments.