fix: handle empty api responses more gracefully

This commit is contained in:
Björn Fromme
2026-03-16 12:03:00 +01:00
parent c597cfda51
commit 6ddd0b00bd
2 changed files with 95 additions and 0 deletions
+17
View File
@@ -688,6 +688,14 @@ class ApiClient
// message length (10 bytes) is prepended to actual message
$xml = substr($response, 10);
if ('' === $xml) {
$this->logger->error('Empty response body received from API (header-only response)', [
'request_id' => $requestId,
'raw_length' => strlen($response),
]);
throw new ApiClientException('Empty response body received from API');
}
if (true === $debug || true === $this->config['debug']) {
$this->dumpXmlToFile('response', $requestId, $xml);
}
@@ -898,6 +906,15 @@ class ApiClient
$response .= $chunk;
}
if (0 === strlen($response)) {
$elapsedTime = microtime(true) - $this->operationStartTime;
$this->logger->warning('Server closed connection without sending data', [
'elapsed_time' => $elapsedTime,
'read_attempts' => $readAttempts,
]);
throw new ImmediateConnectionCloseException('Server closed connection without sending data');
}
return $response;
}