Improved attachment retrieval and added test cases
This commit is contained in:
1 parent
6f2fd40464
commit
fde9661c2c
4 files changed
+91
-2
No files matched your search
@@ -680,9 +680,30 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
|
||||
$this->putIntoCache($cacheId, $fileData, 0);
|
||||
|
||||
$this->logInfoWithTime('Fetched attachment <'.$filename.'> for <'.$object->getId().'> from Core API ['.$response->getStatusCode().'].', $ts);
|
||||
} catch (ConnectException $e) {
|
||||
// connection failed or timed out
|
||||
$this->logInfoWithTime('Attachment <'.$filename.'> for <'.$object->getId().'> could not be retrieved from Core API (connection failed).', $ts);
|
||||
throw new CoreAPIException($e->getMessage(), $e);
|
||||
} catch (RequestException $e) {
|
||||
if ($e->hasResponse() && $e->getResponse()->getStatusCode() == 404) {
|
||||
// not found (404)
|
||||
$this->logInfoWithTime('Attachment <'.$filename.'> for <'.$object->getId().'> not found in Core API.', $ts);
|
||||
return null;
|
||||
} else
|
||||
if ($e->hasResponse()) {
|
||||
// other API error (4xx, 5xx)
|
||||
$statusCode = $e->getResponse()->getStatusCode();
|
||||
$this->logInfoWithTime('Attachment <'.$filename.'> for <'.$object->getId().'> could not be retrieved from Core API ['.$statusCode.'].', $ts);
|
||||
throw new CoreAPIException($e->getMessage(), $e);
|
||||
} else {
|
||||
// API error without response
|
||||
$this->logInfoWithTime('Attachment <'.$filename.'> for <'.$object->getId().'> could not be retrieved from Core API (no status code).', $ts);
|
||||
throw new CoreAPIException($e->getMessage(), $e);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->logInfoWithTime('Attachment <'.$filename.'> for <'.$object->getId().'> not found in Core API ['.$e->getResponse()->getStatusCode().'].', $ts);
|
||||
// ignore exception - treat as non-existing file
|
||||
// other exceptions
|
||||
$this->logInfoWithTime('Attachment <'.$filename.'> for <'.$object->getId().'> could not be retrieved from Core API (unexpected exception).', $ts);
|
||||
throw new CoreAPIException($e->getMessage(), $e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user