Software⏱️ 3 min read📅 2026-06-03

How to Fix: JavaScript fetch - Failed to execute 'json' on 'Response': body stream is locked

Fetch API error: Failed to execute 'json' on 'Response': body stream is locked. This occurs when the request status is greater than 400, preventing the response from being parsed as JSON.

Quick Answer: To resolve this issue, ensure that the fetch request's `mode` option is set to `'cors'` or `'no-cors'`, depending on your specific use case. Alternatively, you can use the `response.json()` method with a try-catch block to handle errors and parse the response as JSON.

When the request status is greater than 400, fetch cannot read the returned JSON content. This issue affects developers who rely on fetching data from APIs or servers that return HTTP responses with statuses above 400.

The problem occurs because the `json()` method expects a response body that can be parsed as JSON, but when the response status is greater than 400, the body stream is locked, preventing it from being read. This issue has been present for several months and affects developers who have continued to use fetch without addressing this problem.

To resolve this issue, you need to check the HTTP response status and handle any errors that may occur when trying to parse the response body as JSON.

⚠️ Common Causes

  • The primary cause of this issue is that the server or API returns an HTTP response with a status code greater than 400. This means that the request was not successful, and the response body cannot be parsed as JSON.
  • Another possible cause is that there is a problem with the network connection or the server's ability to handle requests. In some cases, the issue may be related to the browser's cache or cookies.

✅ Best Solutions to Fix It

Check the HTTP Response Status

  1. Step 1: When making a fetch request, check the response status using the `ok` property of the response object.
  2. Step 2: If the status is greater than 400, handle the error and do not try to parse the response body as JSON. Instead, display an error message to the user or provide alternative options for resolving the issue.
  3. Step 3: For example, you can use a try-catch block to catch any errors that occur when trying to parse the response body as JSON.

Use Error Handling

  1. Step 1: When making a fetch request, add error handling to catch any errors that may occur when trying to parse the response body as JSON.
  2. Step 2: Use the `catch` block of the Promise to handle any errors that occur when trying to parse the response body as JSON.
  3. Step 3: In this case, you can log the error and display an error message to the user or provide alternative options for resolving the issue.

💡 Conclusion

By checking the HTTP response status and adding error handling, you can resolve the issue of fetch failing to execute 'json' on 'Response': body stream is locked. Remember to always check the response status and handle any errors that may occur when trying to parse the response body as JSON.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions