Skip to content

Commit 04cdca0

Browse files
authored
curl throw exception (#363)
1 parent b20c9fb commit 04cdca0

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

resources/autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
require_once __DIR__ . "/lib/exceptions/NoDieException.php";
2929
require_once __DIR__ . "/lib/exceptions/SSOException.php";
3030
require_once __DIR__ . "/lib/exceptions/ArrayKeyException.php";
31+
require_once __DIR__ . "/lib/exceptions/CurlException.php";
3132
require_once __DIR__ . "/lib/exceptions/EntryNotFoundException.php";
3233
require_once __DIR__ . "/lib/exceptions/EnsureException.php";
3334
require_once __DIR__ . "/lib/exceptions/EncodingUnknownException.php";

resources/lib/UnityGithub.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace UnityWebPortal\lib;
4+
use UnityWebPortal\lib\exceptions\CurlException;
45

56
class UnityGithub
67
{
@@ -13,7 +14,11 @@ public function getSshPublicKeys(string $username): array
1314
curl_setopt($curl, CURLOPT_URL, $url);
1415
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1516
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
16-
$keys = json_decode(curl_exec($curl), false);
17+
$curl_output = curl_exec($curl);
18+
if ($curl_output === false) {
19+
throw new CurlException(curl_error($curl));
20+
}
21+
$keys = json_decode($curl_output, false);
1722
curl_close($curl);
1823

1924
// normally returns array of objects each with a ->key attribute
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace UnityWebPortal\lib\exceptions;
4+
5+
class CurlException extends \Exception {}

test/phpunit-bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require_once __DIR__ . "/../resources/lib/exceptions/NoDieException.php";
2020
require_once __DIR__ . "/../resources/lib/exceptions/SSOException.php";
2121
require_once __DIR__ . "/../resources/lib/exceptions/ArrayKeyException.php";
22+
require_once __DIR__ . "/../resources/lib/exceptions/CurlException.php";
2223
require_once __DIR__ . "/../resources/lib/exceptions/EntryNotFoundException.php";
2324
require_once __DIR__ . "/../resources/lib/exceptions/EnsureException.php";
2425
require_once __DIR__ . "/../resources/lib/exceptions/EncodingUnknownException.php";

0 commit comments

Comments
 (0)