Changeset View
Changeset View
Standalone View
Standalone View
src/future/wordpress/PhutilWordPressFuture.php
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | final class PhutilWordPressFuture extends FutureProxy { | ||||
protected function didReceiveResult($result) { | protected function didReceiveResult($result) { | ||||
list($status, $body, $headers) = $result; | list($status, $body, $headers) = $result; | ||||
if ($status->isError()) { | if ($status->isError()) { | ||||
throw $status; | throw $status; | ||||
} | } | ||||
try { | |||||
$data = phutil_json_decode($body); | $data = phutil_json_decode($body); | ||||
if (empty($data)) { | } catch (PhutilJSONParserException $ex) { | ||||
throw new Exception( | throw new PhutilProxyException( | ||||
pht('Expected JSON response from WordPress.com, got: %s', $body)); | pht('Expected JSON response from WordPress.com.'), | ||||
$ex); | |||||
} | } | ||||
if (idx($data, 'error')) { | if (idx($data, 'error')) { | ||||
$error = $data['error']; | $error = $data['error']; | ||||
throw new Exception( | throw new Exception( | ||||
pht('Received error from WordPress.com: %s', $error)); | pht('Received error from WordPress.com: %s', $error)); | ||||
} | } | ||||
return $data; | return $data; | ||||
} | } | ||||
} | } |