Skip to content
This repository was archived by the owner on Jul 28, 2024. It is now read-only.
This repository was archived by the owner on Jul 28, 2024. It is now read-only.

Improve invalid REST API response handling #1074

@borekb

Description

@borekb

In #984, we've worked around the situation where the server (REST API) sends a malformed response, e.g., by including a PHP notice from some plugin. The __VP__ key has been added to every JSON response so that the client-side JavaScript code can understand what is the real response. However, after some internal discussion, we're not sure this is the right approach.

This issue is about reconsidering our options here. Some initial comments:

  • The current approach (as per Make AJAX work with PHP error / notice output #984) modifies the object and feels slightly weird. We'll probably abandon it.

  • Every response could be wrapped in an object like this:

    {
      __VP__: true,
      data: theActualValue
    }
    

    The client would use something like response.body.data.theActualValue instead of response.body.theActualValue. This would also provide the opportunity to send additional metadata with every response should we need that, like what VersionPress or WP version are running on the server.

  • The client could also reject to work if the response is malformed. I think we considered this Make AJAX work with PHP error / notice output #984 but in the end decided it is better for the users if the UI works despite some warnings in it. However, it could be argued that sending notices and such to the client is a security risk / server misconfiguration and we could just show some good error to guide the users to fix their server setup. This is a valid approach.

Let's do some research because the other projects relying on WP REST API must hit the same issue as well.

Metadata

Metadata

Assignees

Labels

improvementImprovement of an existing functionality. See "feature" for new features.noteworthySignificant issue or PR, to be highlighted in release notesscope: coreCore VersionPress functionality like tracking actions, creating Git commits, etc.scope: frontendThe 'frontend' React app and other UI things

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions