Simulating 500 HTTP status code in Create Tweet API on Twitter
Tags: mockapi, testing, requestly, httpstatuscode
Published: 2021-12-29 19:40:52

---
title: Simulating 500 HTTP status code in Create Tweet API on Twitter
published: true
date: 2021-12-29 13:18:15 UTC
tags: mockapi,testing,requestly,httpstatuscode
canonical_url: https://requestly.com/blog/simulating-500-status-code-in-create-tweet-api-on-twitter/
---

Nobody wants to see errors in their API. But they appear at times when least expected. The possible scenarios when an error pops up could be something is wrong with the request or some problem with the API. Whatever may be the cause, one thing is sure traffic would stop.

API crashes shouldn’t disrupt the user experience. Errors should be handled at the client-side so that the user knows that something is wrong and can move on from there.

In the development phase, API consumers won’t wait until the API is entirely built to start their development. In this scenario, they can mock server responses and begin their development. Testing the application for error responses is crucial so that user traffic is not blocked.

A QA tester or Product manager would want to mock various error responses to check how the application handles the errors.

### How to Simulate API error responses using Requestly

[Requestly](https://requestly.com) is a tool that intercepts all the network requests and allows users to modify them. It enables users to Modify Headers, Redirect URLs, Switch hosts, Mock API responses, Delay network requests, Insert custom scripts. It is available as a desktop app and browser extension on all major browsers.

[Requestly](https://app.requestly.io) app can simulate status code responses by using the redirect rule to redirect to a mock API that overrides the status code. In simple words, you are hitting the mock API instead of the actual API.

![](https://cdn-images-1.medium.com/max/1024/0*NROtXIhya1N8HXWF.png)

I used it to simulate status code responses on Twitter

I tried this with the following sites to see how the site handles the simulation of 500- Internal Server Error status code.

### Simulating 500 status code when Tweeting

I created a mock API using requestly setting Status Code as 500.

![](https://cdn-images-1.medium.com/max/1024/0*KTVigYt_Edl5s8lX.png)
_Mock for simulating 500 error response on Twitter_

After some reverse engineering, I noticed that when the tweet button is clicked, a POST request is sent to a Twitter API ending with CreateTweet.

So I created the Requestly rule to be applied only when the URL matches \*/CreateTweet using wildcard match.

![](https://cdn-images-1.medium.com/max/1024/0*3uRwF1N7V1FXLRy5.png)
_Redirect Rule redirecting to mock API_

The redirection to mock API won’t work due to [Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy)- [connect-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/connect-src) directive, which restricts the URLs loaded using script interfaces.

You can use the [Requestly marketplace](https://app.requestly.io/marketplace) rule to bypass this, which is a prebuilt rule to remove the content-security-policy header.

![](https://cdn-images-1.medium.com/max/1024/0*GnwhfkhMZD53HeMt.png)
_Requestly Marketplace_

When I tried tweeting something, 500 status code was simulated and handled as following.

![](https://cdn-images-1.medium.com/max/1024/0*lW-LDuIQpcrUcU40.png)
_500 error response simulated when tweeting_

Get the rule here- [https://app.requestly.io/rules/#sharedList/1640613384657-twitter-500-simulate](https://app.requestly.io/rules/#sharedList/1640613384657-twitter-500-simulate)

This is how I used Requestly to simulate 500 when tweeting. I hope this article has helped you and empowers you to simulate different status codes.

Happy Debugging!

Further Resources:

- [Simulate different API status code using Requestly](https://dev.to/requestlyio/simulate-different-api-status-code-using-requestly-1hd9)
- [Simulating 404 on Blinkit Search](https://dev.to/requestlyio/simulating-404-http-status-code-in-blinkit-search-api-2mgh)

By [@nafees87n](https://www.linkedin.com/in/nafees87n/)

_Originally published at_ [_https://requestly.com_](https://requestly.com/blog/simulating-500-status-code-in-create-tweet-api-on-twitter/)_._