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

Standardise error responses for the rest endpoint #4

Merged

Conversation

mecachisenros
Copy link

Overview

  • Standardise error responses for the rest endpoint to be event with extern/rest.php, instead of returning a WP_Error we return the API Exception's extraParams.
  • Adds .editorconfig file (seemed a bit overkill to open another PR just for that, but le me know if it's needed).

Before

An error (WP_Error) response would look like:

{
	"code": "civicrm_rest_api_error",
	"message": "Mandatory key(s) missing from params array: contact_type",
	"data": {
		"status": 403
	}
}

After

An error (CiviCRM_API3_Exception) looks like:

{
	"fields": [
		"contact_type"
	],
	"error_code": "mandatory_missing",
	"entity": "Contact",
	"action": "create",
	"is_error": 1,
	"error_message": "Mandatory key(s) missing from params array: contact_type"
}

Comments

For reference see mecachisenros/civicrm-wp-rest/issues/5

Always format the result!
If we call the 'rest' endpoint without json param
we are getting the error in json format
instead of the expected xml format.
@christianwach christianwach merged commit 75475ba into christianwach:evolution Aug 29, 2019
@christianwach
Copy link
Owner

@mecachisenros Thanks!

@mecachisenros mecachisenros deleted the standard-rest-error branch August 29, 2019 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants