chg: [internal] Log exception if exception is thrown during event downloading

pull/5992/head
Jakub Onderka 2020-06-07 20:21:31 +02:00
parent 8a3f92bed8
commit 90498fa1e2
3 changed files with 35 additions and 9 deletions

View File

@ -1424,6 +1424,15 @@ class Event extends AppModel
return $attribute;
}
/**
* Download event from remote server.
*
* @param int $eventId
* @param array $server
* @param null|HttpSocket $HttpSocket
* @return array
* @throws Exception
*/
public function downloadEventFromServer($eventId, $server, $HttpSocket=null)
{
$url = $server['Server']['url'];
@ -1431,10 +1440,18 @@ class Event extends AppModel
$request = $this->setupSyncRequest($server);
$uri = $url . '/events/view/' . $eventId . '/deleted[]:0/deleted[]:1/excludeGalaxy:1';
$response = $HttpSocket->get($uri, $data = '', $request);
if ($response->isOk()) {
return json_decode($response->body, true);
if ($response === false) {
throw new Exception("Could not reach '$uri'.");
} else if (!$response->isOk()) {
throw new Exception("Fetching the '$uri' failed with HTTP error {$response->code}: {$response->reasonPhrase}");
}
return null;
$event = json_decode($response->body, true);
if ($event === null) {
throw new Exception('Could not parse event JSON: ' . json_last_error_msg(), json_last_error());
}
return $event;
}
public function quickDelete($event)

View File

@ -2533,11 +2533,14 @@ class Server extends AppModel
private function __pullEvent($eventId, &$successes, &$fails, $eventModel, $server, $user, $jobId, $force = false)
{
$event = $eventModel->downloadEventFromServer(
$eventId,
$server
);
;
try {
$event = $eventModel->downloadEventFromServer($eventId, $server);
} catch (Exception $e) {
$this->logException('Failed downloading the event ' . $eventId, $e);
$fails[$eventId] = __('failed downloading the event');
return false;
}
if (!empty($event)) {
if ($this->__checkIfEventIsBlockedBeforePull($event)) {
return false;

View File

@ -817,7 +817,13 @@ class Sighting extends AppModel
if (!empty($eventIds)) {
// download each event and save sightings
foreach ($eventIds as $k => $eventId) {
$event = $this->Event->downloadEventFromServer($eventId, $server);
try {
$event = $this->Event->downloadEventFromServer($eventId, $server);
} catch (Exception $e) {
$this->logException('Failed downloading the event ' . $eventId, $e);
continue;
}
$sightings = array();
if(!empty($event) && !empty($event['Event']['Attribute'])) {
foreach($event['Event']['Attribute'] as $attribute) {