Better handling of error with git forges APIs
Note to self: Gitlab deprecated APIv3, had to update the link to v4
This commit is contained in:
parent
62df3fddb5
commit
17c4ebe5f6
13
index.php
13
index.php
|
@ -348,7 +348,8 @@ function updateGitKeys($api, $keys)
|
|||
function apiRequest($api, $route, $meth = 'GET', $data = null)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $api['api'].'/'.$route);
|
||||
$url = $api['api'].'/'.$route;
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $meth);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Machines Frogeye');
|
||||
if ($data) {
|
||||
|
@ -366,7 +367,12 @@ function updateGitKeys($api, $keys)
|
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$raw = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return json_decode($raw);
|
||||
$json = json_decode($raw);
|
||||
if ($json !== null && isset($json->{"error"})) {
|
||||
echo("Error with API ".$url.": ".$json->{"error"}."\n");
|
||||
return null;
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
global $SSH_KEY_REGEX;
|
||||
|
@ -403,7 +409,6 @@ function updateGitKeys($api, $keys)
|
|||
}
|
||||
|
||||
foreach ($toDelete as $id => $ekey) {
|
||||
echo "387 deleting $id $ekey\n";
|
||||
apiRequest($api, 'user/keys/'.$id, 'DELETE');
|
||||
}
|
||||
}
|
||||
|
@ -657,7 +662,7 @@ case 'config':
|
|||
|
||||
foreach ($machines as $dMachineName => $dMachine) {
|
||||
if ($network['secure'] == 'true') {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue