Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change HTTP Response Code for Unauthorized REST Access #2170

Open
Mwalek opened this issue Oct 15, 2024 · 0 comments
Open

Change HTTP Response Code for Unauthorized REST Access #2170

Mwalek opened this issue Oct 15, 2024 · 0 comments

Comments

@Mwalek
Copy link

Mwalek commented Oct 15, 2024

Currently, when REST access for a View is not enabled, GravityView responds with an HTTP 500 error. This can lead to confusion for developers and users trying to troubleshoot issues related to REST API access. This enhancement proposes changing the response code to 401 (Unauthorized) to better reflect the nature of the error.

Steps to Reproduce:

  1. Create a View in GravityView.
  2. Make sure REST access is NOT allowed for the created View (Under Permissions).
  3. Attempt to access the View via the REST API. Ref: https://docs.gravitykit.com/article/468-rest-api

Expected Behavior:
The API should return a 401 Unauthorized status code, indicating that access to the View is not permitted due to disabled REST access.

Actual Behavior:
The API currently returns a 500 Internal Server Error, which does not provide a clear indication of the issue related to REST access.

Solution direction
WP_Error has a $data array, which can have a status key. This status will be used instead of the default 500; when provided.

Screenshot 2024-10-15 at 6 41 19 AM
@GravityKit GravityKit deleted a comment Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
@Mwalek and others