#35028 closed defect (bug) (fixed)
WP_Error objects returned by REST API validation callbacks aren't formatted correctly
| Reported by: | bradyvercher | Owned by: | joehoyle |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.5 |
| Component: | REST API | Version: | 4.4 |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
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
@
11 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.
#4
@
11 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." } } }