Skip to:
Content

BuddyPress.org

Opened 2 months ago

Closed 2 months ago

#8131 closed enhancement (fixed)

Make bp.apiRequest directly return the BP REST API error instead of the full xhr object.

Reported by: imath Owned by: imath
Milestone: 5.0.0 Priority: normal
Severity: normal Version:
Component: Core Keywords: has-patch
Cc:

Description

I've been testing the function we advise to use to do BP REST API requests in JavaScript a lot since I've checked every endpoints writing the BP REST API documentation.

Something always annoyed me: I had to get the xhr.responseJSON object to get the BP REST API error. I think using the attached patch will improve this by directly returning the BP REST API error for the generic way to deal with error (using the .fail() callback).

I also think it's nice to have a default error in case something goes wrong and we haven't predicted it.

The patch is also improving how $.ajax options are built in case the wp.apiRequest is not available (WordPress 4.7 & 4.8)

Attachments (1)

8131.patch (5.4 KB) - added by imath 2 months ago.

Download all attachments as: .zip

Change History (3)

@imath
2 months ago

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


2 months ago

#2 @imath
2 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 12454:

Improve the bp.apiRequest() JS function and some PHP code indentation

bp.apiRequest() will make sure to return the JSON response object in case of an error. In case this JSON response object is not available a default error object will be used.

When WordPress version is lower than 4.9, the same function will make sure to override the url option with the REST API root URL only if this option is not already set. Moreover the Nonce header is now only added for REST API requests made on the current site domain.

The PHP code indentation of bp-core/bp-core-rest-api.php file has been improved.

Fixes #8131

Note: See TracTickets for help on using tickets.