question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhance error messages for "Invalid JSON Response" errors

See original GitHub issue

Feature Description

The Site Kit API client on the frontend uses @wordpress/api-fetch under the hood which is a layer on top of window.fetch which is designed for interacting with the WordPress REST API. One of the features it provides is to eliminate some of the boilerplate of making fetch requests, such as resolving the JSON body from the response.

The client doesn’t force a JSON response, but it does assume one by default (this can be controlled with an option). In the event that the response is not JSON-parseable (and by default attempts to parse it as such), the client will throw a generic (and very familiar looking) invalid_json error.

This is not particularly useful to the average end user and often leads to support requests which are difficult to provide good support for due to the limited information. Accordingly, we should enhance our error handling in such cases to provide more useful, or at the very least – less cryptic messaging to the end user, and where possible additional context for support.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Site Kit should never display a “The response is not a valid JSON response” error message to the end user as part of its user-facing interface (console messages/logging are fine because this is developer-centric tooling)
  • Instead, it should show the following, based on a few other conditions:
    • If the response status code is 504: The service took too long to respond. (see #4504 for reference)
    • TODO: Define other conditions.
    • Otherwise: The service provided an invalid response.
  • In all of the above cases, the error should be accompanied with the Retry button implemented via TODO (add issue link here for error notifications MVP issue to implement that).

Implementation Brief

Test Coverage

QA Brief

Changelog entry

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
felixarntzcommented, Sep 20, 2022

The ACs newly defined on #4997 cover this issue as well as it’s closely related. Please follow along the other issue going forward, closing this as a duplicate.

1reaction
aaemnnosttvcommented, Apr 6, 2022

What do we want to show instead?

@felixarntz I meant to ask you about it, this was just intended to be a starting point so far.

As for what we show instead, it could be contextual similar to #4997 (this is mostly relevant for ReportError anyways I think 🤔 ). Essentially a more useful message for the user that potentially links to some SK docs for troubleshooting.

What should we do if the response is not JSON?

That’s usually the reason for the error in the first place! 😄 Another case though could be corrupted JSON, if for example, a PHP Notice were output right before the otherwise valid JSON response, or even an empty response body would also be invalid – although an HTML response could also raise this error. There are a number of things we probably could do but we could probably improve the end user experience quite a bit with even a small change (again, similar to #4997).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix the Invalid JSON Response Error in WordPress
Learn what's causing the invalid JSON response error on your WordPress site as well as the different ways you can fix it.
Read more >
How to Fix the Invalid JSON Error in WordPress? - Rank Math
In this article, learn how to fix the invalid JSON error - 'Updating failed. The response is not a valid JSON response.' with...
Read more >
How to Fix “The Response Is Not a Valid JSON ... - iThemes
This guide explains how the Gutenberg editor works with REST API and how to fix "The response is not a valid JSON response"...
Read more >
How to Fix The Invalid JSON Error in WordPress (Beginner's ...
This error appears when editing WordPress posts or pages on your website. You'll see a message saying 'The response is not a valid...
Read more >
6 Fixes for "the response is not a valid JSON response" Error in
Before you try anything else, you should try resetting your permalinks to resolve the invalid JSON response error. Navigate to Settings > ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found