Skip to content

Commit

Permalink
Properly catch exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
GuLinux committed Jan 1, 2018
1 parent 844e028 commit 321a88e
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions classes/AstrobinAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
class AstrobinAPIException extends \Exception {
public function __construct($obj)
{
parent::__construct("Error during Astrobin API call with code " . $obj['code'] . ": " . $obj['message'], $obj['code'], null);
Grav::instance()['debugger']->addMessage('Astrobin API error: ' . $obj->getCode() . ', ' . $obj->getMessage());
parent::__construct("Error during Astrobin API call with code " . $obj->getCode(), $obj->getCode(), null);
}
}

Expand Down Expand Up @@ -47,13 +48,9 @@ public function image($id)

public function image_by_uri($uri, $has_prefix = false)
{
try {
$info = $this->request($uri, [], ! $has_prefix);
if($info != NULL)
return new Image($info, $this);
} catch(RuntimeException $e) {
$grav['debugger']->addMessage("Error while getting image by uri " . $uri . ": " . $e);
}
$info = $this->request($uri, [], ! $has_prefix);
if($info != NULL)
return new Image($info, $this);
return NULL;
}

Expand Down Expand Up @@ -84,7 +81,7 @@ public function request($path, $params = [], $add_prefix = true) {
$this->cache->save($url, $obj, $this->cache_duration);
}
return $obj;
} catch(Exception $e) {
} catch(\Exception $e) {
throw new AstrobinAPIException($e);
}
}
Expand Down

0 comments on commit 321a88e

Please sign in to comment.