Improved exception handling

This commit is contained in:
lukas committed 2026-10-16 08:38:08 +00:00
1 parent 70c52b8ad2
commit 12ed032a31
3 files changed
+50 -9

No files matched your search

+22 -9
View File
@@ -283,11 +283,24 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
$this->putIntoCache($uriString, $object, $this->options['cache_ttl']);
$this->logInfoWithTime('Fetched <'.$uriString.'> from Core API ['.$response->getStatusCode().'].', $ts);
} catch (RequestException $e) {
if ($e->hasResponse())
$this->logInfoWithTime('Object <'.$uriString.'> not found in Core API ['.$e->getResponse()->getStatusCode().'].', $ts);
else
$this->logInfoWithTime('Object <'.$uriString.'> could not be retrieved from Core API.', $ts);
return null;
if ($e->hasResponse() && $e->getResponse()->getStatusCode() == 404) {
// not found
$this->logInfoWithTime('Object <'.$uriString.'> not found in Core API.', $ts);
return null;
} else
if ($e->hasResponse()) {
// other API error
$this->logInfoWithTime('Object <'.$uriString.'> could not be retrieved from Core API ['.$e->getResponse()->getStatusCode().'].', $ts);
throw new CoreAPIException($e->getMessage(), $e);
} else {
// API error without response
$this->logInfoWithTime('Object <'.$uriString.'> could not be retrieved from Core API (no status code).', $ts);
throw new CoreAPIException($e->getMessage(), $e);
}
} catch (Exception $e) {
// other exceptions
$this->logInfoWithTime('Object <'.$uriString.'> could not be retrieved from Core API (unexpected exception).', $ts);
throw new CoreAPIException($e->getMessage(), $e);
}
}
@@ -337,7 +350,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
$this->logInfoWithTime('Fetched all objects with <'.$type.'> for <'.$namespaceCoid->getHost().'> from Core API ['.$response->getStatusCode().'].', $ts);
} catch (Exception $e) {
throw new CoreAPIException;
throw new CoreAPIException($e->getMessage(), $e);
}
return $allIris;
@@ -379,7 +392,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
$this->logInfoWithTime('Fetched all objects for <'.$namespaceCoid->getHost().'> from Core API ['.$response->getStatusCode().'].', $ts);
} catch (Exception $e) {
throw new CoreAPIException;
throw new CoreAPIException($e->getMessage(), $e);
}
return $allIris;
@@ -413,7 +426,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
$this->logInfoWithTime('Fetched object list for <'.$namespaceCoid->getHost().'> from Core API ['.$response->getStatusCode().'].', $ts);
} catch (Exception $e) {
throw new CoreAPIException;
throw new CoreAPIException($e->getMessage(), $e);
}
return $allIris;
@@ -452,7 +465,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
$this->logInfoWithTime('Fetched object list with <'.$type.'> for <'.$namespaceCoid->getHost().'> from Core API ['.$response->getStatusCode().'].', $ts);
} catch (Exception $e) {
throw new CoreAPIException;
throw new CoreAPIException($e->getMessage(), $e);
}
return $allIris;