Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#38547 closed defect (bug) (fixed)

REST-API Json decode error will not give back an error

Reported by: danielhuesken's profile danielhuesken Owned by: rmccue's profile rmccue
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.6.1
Component: REST API Keywords:
Focuses: Cc:


If you send a Request to the Rest API with a defect json in body than it will not return a error. That is not so good, because you get back a response that suggest all is ok.

Method: POST

The problem is located at:

The 'return;' let it looks like all is ok and the answere will be the normel responce.

Attachments (1)

38547.diff (3.0 KB) - added by rmccue 8 years ago.
Check for JSON encoding errors in has_valid_params

Download all attachments as: .zip

Change History (7)

#1 @joehoyle
8 years ago

Thanks @danielhuesken for the report! This seems legitimate to me. Throwing an error would help a lot for API clients that send malformed JSON - however we'll (maybe) want to make sure that if you send _both_ (I don't even know if that's possible) that we don't have a BC issue.

#2 @danielhuesken
8 years ago

Can it be a solution, to set a header with error codes/message? That you have a hint about the problem.

This ticket was mentioned in Slack in #core-restapi by rmccue. View the logs.

8 years ago

#4 @rmccue
8 years ago

  • Milestone changed from Awaiting Review to 4.7
  • Owner set to rmccue
  • Status changed from new to assigned
  • Type changed from enhancement to defect (bug)

8 years ago

Check for JSON encoding errors in has_valid_params

#5 @joehoyle
8 years ago

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

In 39109:

REST API: Return error when JSON decoding fails.

If you send a request to the REST API with invalid JSON in body than it will now return a error. This assists developers if they accidentally send invalid JSON and wonder why their data appears to be ignored.

Props rmccue.
Fixes #38547.

#6 @rmccue
8 years ago

In 39111:

REST API: Only provide JSON error code on PHP 5.3+.

json_last_error() was only added to PHP 5.3.0, so we can't provide the information for older versions.

See #38547.

Note: See TracTickets for help on using tickets.