From 5cc4486d9afbfd4d6687c71b7437fff63a47c642 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Thu, 1 Oct 2026 18:37:14 +0530 Subject: [PATCH] fix(abdm): distinguish ABHA Number vs ABHA Address in lookup error messages and logs --- app/Controllers/Abha.php | 8 ++++++-- app/Libraries/Abdm/EAtriaBridgeConnector.php | 14 +++++++++----- tests/unit/Abdm/AbhaOtpErrorHandlingTest.php | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/Controllers/Abha.php b/app/Controllers/Abha.php index 9252c30..5335cfc 100644 --- a/app/Controllers/Abha.php +++ b/app/Controllers/Abha.php @@ -1714,7 +1714,10 @@ class Abha extends BaseController if (is_string($candidate) && trim($candidate) !== '') { $trimmed = trim($candidate); if (stripos($trimmed, 'preferredAbhaAddress') !== false || (stripos($trimmed, 'Unknown column') !== false && stripos($trimmed, 'where clause') !== false)) { - return 'ABHA Address does not exist or was not found in the ABDM registry.'; + $isNumberLookup = (($result['type'] ?? '') === 'abha-number') + || (isset($result['abha_id']) && !isset($result['abha_address'])) + || (isset($result['value']) && !str_contains((string) $result['value'], '@') && ctype_digit(str_replace(['-', ' '], '', (string) $result['value']))); + return ($isNumberLookup ? 'ABHA Number' : 'ABHA Address') . ' does not exist or was not found in the ABDM registry.'; } if (stripos($trimmed, 'loginHint') !== false && stripos($trimmed, 'invalid') !== false) { return 'ABDM gateway rejected login hint: OTP verification by ABHA Address is not supported directly by ABDM. Please verify using the 14-digit ABHA Number or Find ABHA via Mobile.'; @@ -2862,8 +2865,9 @@ class Abha extends BaseController $errorText .= ' (Ref: ' . $requestId . ')'; } + $entityName = $isAddress ? 'ABHA Address' : 'ABHA Number'; if (stripos($errorText, 'Unknown column') !== false || stripos($errorText, 'preferredAbhaAddress') !== false || stripos($errorText, 'not found') !== false || stripos($errorText, 'does not exist') !== false) { - $errorText = 'ABHA Address does not exist or was not found in the ABDM registry.'; + $errorText = $entityName . ' does not exist or was not found in the ABDM registry.'; } elseif (stripos($errorText, 'Please make a valid request.') !== false) { $errorText = 'Bridge validation rejected this request. Please contact bridge support with the reference shown. ' . $errorText; diff --git a/app/Libraries/Abdm/EAtriaBridgeConnector.php b/app/Libraries/Abdm/EAtriaBridgeConnector.php index f03b583..71005ab 100644 --- a/app/Libraries/Abdm/EAtriaBridgeConnector.php +++ b/app/Libraries/Abdm/EAtriaBridgeConnector.php @@ -499,15 +499,19 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface } } + $targetVal = (string) ($body['value'] ?? $body['abha_address'] ?? $body['abha_id'] ?? ''); + $isNumberLookup = (($body['type'] ?? '') === 'abha-number') + || (isset($body['abha_id']) && !isset($body['abha_address'])) + || (!str_contains($targetVal, '@') && $targetVal !== '' && ctype_digit(str_replace(['-', ' '], '', $targetVal))); + $entityLabel = $isNumberLookup ? 'ABHA Number' : 'ABHA Address'; + // Normalise technical MySQL database errors from the bridge when an ABHA is not found if (stripos($extractedErr, 'preferredAbhaAddress') !== false || (stripos($extractedErr, 'Unknown column') !== false && stripos($extractedErr, 'where clause') !== false)) { - $targetVal = (string) ($body['value'] ?? $body['abha_address'] ?? $body['abha_id'] ?? ''); $decoded['raw_bridge_error'] = $extractedErr; - $extractedErr = 'ABHA Address does not exist or was not found in ABDM registry' . ($targetVal !== '' ? ' (' . $targetVal . ')' : ''); - } elseif (stripos($extractedErr, 'Invalid Login Hint') !== false && stripos($extractedErr, 'ABHA Address') === false) { - $targetVal = (string) ($body['value'] ?? $body['abha_address'] ?? $body['abha_id'] ?? ''); - $extractedErr = 'ABHA Address does not exist or was not found in ABDM registry' . ($targetVal !== '' ? ' (' . $targetVal . ')' : ''); + $extractedErr = $entityLabel . ' does not exist or was not found in ABDM registry' . ($targetVal !== '' ? ' (' . $targetVal . ')' : ''); + } elseif (stripos($extractedErr, 'Invalid Login Hint') !== false || stripos($extractedErr, 'rejected login hint') !== false) { + $extractedErr = $entityLabel . ' does not exist or was not found in ABDM registry' . ($targetVal !== '' ? ' (' . $targetVal . ')' : ''); } if ($extractedErr !== '') { diff --git a/tests/unit/Abdm/AbhaOtpErrorHandlingTest.php b/tests/unit/Abdm/AbhaOtpErrorHandlingTest.php index b41ff0d..44d992d 100644 --- a/tests/unit/Abdm/AbhaOtpErrorHandlingTest.php +++ b/tests/unit/Abdm/AbhaOtpErrorHandlingTest.php @@ -97,6 +97,20 @@ final class AbhaOtpErrorHandlingTest extends CIUnitTestCase $this->assertStringContainsString('ABHA Address does not exist or was not found in the ABDM registry', $result); } + public function testExtractBridgeErrorTextNormalizesUnknownColumnForAbhaNumber(): void + { + $payload = [ + 'ok' => 0, + 'type' => 'abha-number', + 'value' => '91987654321032', + 'error' => "Unknown column 'preferredAbhaAddress' in 'where clause'", + 'request_id' => 'REQ-20261001181024-934fd7ae', + ]; + + $result = $this->extractMethod->invoke($this->controller, $payload, 'ABHA validation failed'); + $this->assertStringContainsString('ABHA Number does not exist or was not found in the ABDM registry', $result); + } + public function testExtractBridgeErrorTextPreservesGenericWhenNoFieldErrors(): void { $payload = [