Change HTTP Response Code for Unauthorized REST Access
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:
- Create a View in GravityView.
- Make sure REST access is NOT allowed for the created View (Under Permissions).
- 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.