diff --git a/app/Lib/Tools/HttpSocketExtended.php b/app/Lib/Tools/HttpSocketExtended.php index 7213fc5fa..9ca042c35 100644 --- a/app/Lib/Tools/HttpSocketExtended.php +++ b/app/Lib/Tools/HttpSocketExtended.php @@ -18,10 +18,15 @@ class HttpSocketHttpException extends Exception { $this->response = $response; $this->url = $url; + $message = "Remote server returns HTTP error code $response->code"; if ($url) { $message .= " for URL $url"; } + if ($response->body) { + $message .= ': ' . substr($response->body, 0, 100); + } + parent::__construct($message, (int)$response->code); } diff --git a/app/Model/Sighting.php b/app/Model/Sighting.php index d19148bf8..7384869b9 100644 --- a/app/Model/Sighting.php +++ b/app/Model/Sighting.php @@ -1017,16 +1017,16 @@ class Sighting extends AppModel * @return TmpFileTool * @throws Exception */ - public function restSearch(array $user, $returnFormat, $filters) + public function restSearch(array $user, $returnFormat, array $filters) { $allowedContext = array('event', 'attribute'); // validate context if (isset($filters['context']) && !in_array($filters['context'], $allowedContext, true)) { - throw new MethodNotAllowedException(__('Invalid context %s.', $filters['context'])); + throw new BadRequestException(__('Invalid context %s.', $filters['context'])); } // ensure that an id or uuid is provided if context is set if (!empty($filters['context']) && !(isset($filters['id']) || isset($filters['uuid'])) ) { - throw new MethodNotAllowedException(__('An ID or UUID must be provided if the context is set.')); + throw new BadRequestException(__('An ID or UUID must be provided if the context is set.')); } if (!isset($this->validFormats[$returnFormat][1])) { @@ -1396,7 +1396,7 @@ class Sighting extends AppModel try { $sightings = $serverSync->fetchSightingsForEvents($chunk); } catch (Exception $e) { - $this->logException("Failed downloading the sightings from {$serverSync->server()['Server']['name']}.", $e); + $this->logException("Failed to download sightings from {$serverSync->server()['Server']['name']}.", $e); continue; }