Fix Bridge ping API action

A follow-up fix for the adjustment made to Bridge ping in "Expand System Info report with MSS connection status" (9b0b43f).

Note that the logic was already flawed prior to the changes introduced in this PR: "pingBridge" of "Bridge" class would never throw an exception.

[MAILPOET-6302]
This commit is contained in:
Mustapha Hadid
2024-12-11 17:15:27 +03:00
committed by Aschepikov
parent ce44e07c59
commit adc91d5451
2 changed files with 20 additions and 14 deletions

View File

@@ -298,15 +298,17 @@ class Services extends APIEndpoint {
}
public function pingBridge() {
try {
$bridgePingResponse = $this->bridge->pingBridge();
} catch (\Exception $e) {
$response = $this->bridge->pingBridge();
if ($this->wp->isWpError($response)) {
/** @var \WP_Error $response */
$errorDesc = $this->getErrorDescriptionByCode(Bridge::CHECK_ERROR_UNKNOWN);
return $this->errorResponse([
APIError::UNKNOWN => $e->getMessage(),
APIError::UNKNOWN => "{$errorDesc}: {$response->get_error_message()}",
]);
}
if (!$this->bridge->validateBridgePingResponse($bridgePingResponse)) {
$code = $bridgePingResponse ?: Bridge::CHECK_ERROR_UNKNOWN;
if (!$this->bridge->validateBridgePingResponse($response)) {
$code = $this->wp->wpRemoteRetrieveResponseCode($response) ?: Bridge::CHECK_ERROR_UNKNOWN;
return $this->errorResponse([
APIError::UNKNOWN => $this->getErrorDescriptionByCode($code),
]);