PR review changes
This commit is contained in:
parent
842045874e
commit
745f657c0d
1 changed files with 15 additions and 13 deletions
|
@ -120,24 +120,26 @@ class Webhooks extends Action
|
||||||
\curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
\curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
$curl_exec_result = \curl_exec($ch);
|
$responseBody = \curl_exec($ch);
|
||||||
|
$curlError = \curl_error($ch);
|
||||||
|
$statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
||||||
|
\curl_close($ch);
|
||||||
|
|
||||||
if (\curl_error($ch) !== '' || \curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 400) {
|
if (!empty($curlError) || $statusCode >= 400) {
|
||||||
$dbForConsole->increaseDocumentAttribute('webhooks', $webhook->getId(), 'attempts', 1);
|
$dbForConsole->increaseDocumentAttribute('webhooks', $webhook->getId(), 'attempts', 1);
|
||||||
$webhook = $dbForConsole->getDocument('webhooks', $webhook->getId());
|
$webhook = $dbForConsole->getDocument('webhooks', $webhook->getId());
|
||||||
$attempts = $webhook->getAttribute('attempts');
|
$attempts = $webhook->getAttribute('attempts');
|
||||||
|
|
||||||
$logs = json_encode([
|
$logs = '';
|
||||||
'URL' => $webhook->getAttribute('url'),
|
$logs .= 'URL: ' . $webhook->getAttribute('url') . "\n";
|
||||||
'Method' => 'POST',
|
$logs .= 'Method: ' . 'POST' . "\n";
|
||||||
]);
|
|
||||||
|
|
||||||
if (\curl_error($ch) !== '') {
|
if (!empty($curlError)) {
|
||||||
$logs['CurlError'] = \curl_error($ch);
|
$logs .= 'CURL Error: ' . $curlError . "\n";
|
||||||
$logs['Events'] = implode(', ', $events);
|
$logs .= 'Events: ' . implode(', ', $events) . "\n";
|
||||||
} else {
|
} else {
|
||||||
$logs['Response status code'] = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
$logs .= 'Status code: ' . $statusCode . "\n";
|
||||||
$logs['Response body'] = $curl_exec_result;
|
$logs .= 'Body: ' . "\n" . \mb_strcut($responseBody, 0, 10000) . "\n"; // Limit to 10kb
|
||||||
}
|
}
|
||||||
|
|
||||||
$webhook->setAttribute('logs', $logs);
|
$webhook->setAttribute('logs', $logs);
|
||||||
|
@ -152,8 +154,8 @@ class Webhooks extends Action
|
||||||
$this->errors[] = $logs;
|
$this->errors[] = $logs;
|
||||||
} else {
|
} else {
|
||||||
$webhook->setAttribute('attempts', 0); // Reset attempts on success
|
$webhook->setAttribute('attempts', 0); // Reset attempts on success
|
||||||
|
$dbForConsole->updateDocument('webhooks', $webhook->getId(), $webhook);
|
||||||
|
$dbForConsole->deleteCachedDocument('projects', $project->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
\curl_close($ch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue