Skip to content

Commit

Permalink
Improve error reporting for reddit spout
Browse files Browse the repository at this point in the history
Closes: #633
  • Loading branch information
jtojnar committed Feb 5, 2017
1 parent b25ee2c commit 67c1123
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions spouts/reddit/reddit2.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,25 @@ public function load( $params ) {

if (!empty($params['password']) && !empty($params['username'])) {
if (function_exists("apc_fetch")) {
$this->reddit_session = apc_fetch("{$params['username']}_slefoss_reddit_session");
$this->reddit_session = apc_fetch("{$params['username']}_selfoss_reddit_session");
if (empty($this->reddit_session)) {
$this->login($params);
}
}else{
$this->login($params);
}
}

$json = json_decode($this->file_get_contents_curl("https://www.reddit.com/" . $params['url'] . ".json"));

if ($json === null) {
throw new \Exception("Cannot parse the response.");
}

if (isset($json->error)) {
throw new \Exception($json->message);
}

$this->items = $json->data->children;
}

Expand Down Expand Up @@ -480,11 +490,15 @@ private function login($params)
$response = curl_exec($ch);
$response = json_decode($response);
if (curl_errno($ch)) {
print(curl_error($ch));
throw new \Exception(curl_error($ch));
} else {
curl_close($ch);
if (count($response->json->errors) > 0){
print($response);
$errors = '';
foreach ($response->json->errors as $error) {
$errors .= $error[1] . PHP_EOL;
}
throw new \Exception($errors);
} else {
$this->reddit_session = "reddit_session={$response->json->data->cookie}";
if (function_exists("apc_store")) {
Expand Down

0 comments on commit 67c1123

Please sign in to comment.