#35028 closed defect (bug) (fixed)
WP_Error objects returned by REST API validation callbacks aren't formatted correctly
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.5 | Priority: | normal |
| Severity: | normal | Version: | 4.4 |
| Component: | REST API | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
Here's an example response with two missing parameters. The software_id validation callback returns a WP_Error instance, while the software_version is required, but doesn't have a validation callback defined.
{
"code":"rest_invalid_param",
"message":"Invalid parameter(s): software_id (Invalid software identifier.), Invalid parameter.",
"data":{
"status":400,
"params":{
"0":"software_id (Invalid software identifier.)",
"software_version":"Invalid parameter."
}
}
}
Attachments (1)
Change History (7)
#2
@
10 years ago
- Keywords needs-unit-tests added
There are couple of tests for the has_valid_params() method already. It would be good to have a test for this as well.
#3
@
10 years ago
- Owner set to joehoyle
- Resolution set to fixed
- Status changed from new to closed
In 35890:
#4
@
10 years ago
I updated the response format to be:
{
"code":"rest_invalid_param",
"message":"Invalid parameter(s): software_id, software_version",
"data":{
"status":400,
"params":{
"software_id":"Invalid software identifier.",
"software_version":"Invalid parameter."
}
}
}
This makes it a bit more readable too. Also, added unit tests for returning a WP_Error from the validate callback. Thanks bradyvercher!
Note: See
TracTickets for help on using
tickets.
Here's how the same response is formatted with the attached patch applied:
{ "code":"rest_invalid_param", "message":"Invalid parameter(s): Invalid software identifier., Invalid parameter.", "data":{ "status":400, "params":{ "software_id":"Invalid software identifier.", "software_version":"Invalid parameter." } } }