foreach ($allLinks as $fb => $link) {
// Error code start with 4 or 5
// Redirection code start with 3
- $curlResponse = FluidbookAuditLink::getHttpCode($link['url']);
+ try {
+ $curlResponse = FluidbookAuditLink::getHttpCode($link['url']);
+ }catch (\Error $e) {
+ echo "Error when trying to get http code: " . $e->getMessage().PHP_EOL;
+ continue;
+ }catch (\Exception $e) {
+ echo "Exception when trying to get http code: " . $e->getMessage() . PHP_EOL;
+ continue;
+ }
+
$httpCode = $curlResponse['httpcode'];
$finalurl = '';
$finalcodeurl = '';
}
}
- if(str_starts_with($httpCode, 3)) {
- $finalurl = $curlResponse['finalurl'];
- $finalcodeurl = FluidbookAuditLink::getHttpCode($curlResponse['finalurl'])['httpcode'];
+ if (str_starts_with($httpCode, 3)) {
+ try {
+ $finalurl = $curlResponse['finalurl'];
+ $finalcodeurl = FluidbookAuditLink::getHttpCode($curlResponse['finalurl'])['httpcode'];
+ }catch (\Error $e) {
+ echo "Error when trying to get final url: " . $e->getMessage().PHP_EOL;
+ continue;
+ }catch (\Exception $e) {
+ echo "Exception when trying to get final url: " . $e->getMessage() . PHP_EOL;
+ continue;
+ }
}
$comment = FluidbookAuditLink::getHttpCodeComment($httpCode);
];
}
- $keys = array_slice(array_keys($externalLinks[0]), 1);
+ if($externalLinks) {
+ $keys = array_slice(array_keys($externalLinks[0]), 1);
- DB::table('fluidbook_audit_link')->upsert($externalLinks, ['id'], $keys);
+ DB::table('fluidbook_audit_link')->upsert($externalLinks, ['id'], $keys);
+ }
Log::info('Job exécuté avec succès');
}