private function getFallbackOrThrowException(Exception $originalException = null)
{
$metrics = $this->getMetrics();
$message = $originalException === null ? 'Short-circuited' : $originalException->getMessage();
try {
if ($this->config->get('fallback')->get('enabled')) {
try {
$executionResult = $this->getFallback();
$metrics->markFallbackSuccess();
$this->recordExecutionEvent(self::EVENT_FALLBACK_SUCCESS);
return $executionResult;
} catch (FallbackNotAvailableException $fallbackException) {
throw new RuntimeException($message . ' and no fallback available', get_class($this), $originalException);
} catch (Exception $fallbackException) {
$metrics->markFallbackFailure();
$this->recordExecutionEvent(self::EVENT_FALLBACK_FAILURE);
throw new RuntimeException($message . ' and failed retrieving fallback', get_class($this), $originalException, $fallbackException);
}
} else {
throw new RuntimeException($message . ' and fallback disabled', get_class($this), $originalException);
}
} catch (Exception $exception) {
// count that we are throwing an exception and re-throw it
$metrics->markExceptionThrown();
$this->recordExecutionEvent(self::EVENT_EXCEPTION_THROWN);
throw $exception;
}
}