GravityView icon indicating copy to clipboard operation
GravityView copied to clipboard

Change HTTP Response Code for Unauthorized REST Access

Open Mwalek opened this issue 1 year ago • 0 comments

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

Mwalek avatar Oct 15 '24 08:10 Mwalek