fix(abdm): normalize bridge SQL errors in API logs and extract specific upstream hints
This commit is contained in:
parent
fd10df43c3
commit
7c1f0df410
|
|
@ -1680,12 +1680,14 @@ class Abha extends BaseController
|
|||
{
|
||||
$candidates = [
|
||||
$result['error_text'] ?? null,
|
||||
is_string($result['error'] ?? null) ? $result['error'] : null,
|
||||
$result['message'] ?? null,
|
||||
$result['error']['message'] ?? null,
|
||||
$result['error']['description'] ?? null,
|
||||
$result['error']['code'] ?? null,
|
||||
$result['error']['error'] ?? null,
|
||||
$result['error']['error_description'] ?? null,
|
||||
is_string($result['data']['error'] ?? null) ? $result['data']['error'] : null,
|
||||
$result['data']['message'] ?? null,
|
||||
$result['data']['error']['message'] ?? null,
|
||||
$result['data']['error']['description'] ?? null,
|
||||
|
|
@ -1711,6 +1713,9 @@ class Abha extends BaseController
|
|||
foreach ($candidates as $candidate) {
|
||||
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.';
|
||||
}
|
||||
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.';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -469,10 +469,49 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface
|
|||
$ok = 0;
|
||||
}
|
||||
|
||||
if ($ok === 0 && empty($decoded['error_text'])) {
|
||||
$errMsg = trim((string) ($decoded['message'] ?? $decoded['data']['message'] ?? $decoded['error']['message'] ?? (is_string($decoded['error'] ?? null) ? $decoded['error'] : '')));
|
||||
if ($errMsg !== '') {
|
||||
$decoded['error_text'] = $errMsg;
|
||||
if ($ok === 0) {
|
||||
$extractedErr = '';
|
||||
|
||||
// Check for specific rejection data inside data (e.g. loginHint, details)
|
||||
if (isset($decoded['data']) && is_array($decoded['data'])) {
|
||||
if (!empty($decoded['data']['loginHint'])) {
|
||||
$hint = trim((string) $decoded['data']['loginHint']);
|
||||
$extractedErr = 'ABDM gateway rejected login hint: ' . $hint . ' (ABHA Address or number not found)';
|
||||
} elseif (!empty($decoded['data']['details'][0]['message'])) {
|
||||
$extractedErr = trim((string) $decoded['data']['details'][0]['message']);
|
||||
} elseif (!empty($decoded['data']['message'])) {
|
||||
$extractedErr = trim((string) $decoded['data']['message']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($extractedErr === '' && isset($decoded['error']) && is_array($decoded['error'])) {
|
||||
if (!empty($decoded['error']['details'][0]['message'])) {
|
||||
$extractedErr = trim((string) $decoded['error']['details'][0]['message']);
|
||||
} elseif (!empty($decoded['error']['message']) && $decoded['error']['message'] !== 'ABDM gateway returned an error.') {
|
||||
$extractedErr = trim((string) $decoded['error']['message']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($extractedErr === '') {
|
||||
$rawMsg = trim((string) ($decoded['message'] ?? $decoded['data']['message'] ?? $decoded['error']['message'] ?? (is_string($decoded['error'] ?? null) ? $decoded['error'] : '')));
|
||||
if ($rawMsg !== '') {
|
||||
$extractedErr = $rawMsg;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 . ')' : '');
|
||||
}
|
||||
|
||||
if ($extractedErr !== '') {
|
||||
$decoded['error_text'] = $extractedErr;
|
||||
}
|
||||
}
|
||||
$logErr = $ok === 0 ? (string) ($decoded['error_text'] ?? $decoded['message'] ?? '') : '';
|
||||
|
|
|
|||
|
|
@ -85,6 +85,18 @@ final class AbhaOtpErrorHandlingTest extends CIUnitTestCase
|
|||
$this->assertStringNotContainsString('ABDM gateway returned an error.', $result);
|
||||
}
|
||||
|
||||
public function testExtractBridgeErrorTextNormalizesUnknownColumnPreferredAbhaAddress(): void
|
||||
{
|
||||
$payload = [
|
||||
'ok' => 0,
|
||||
'error' => "Unknown column 'preferredAbhaAddress' in 'where clause'",
|
||||
'request_id' => 'REQ-20261001170423-8270515b',
|
||||
];
|
||||
|
||||
$result = $this->extractMethod->invoke($this->controller, $payload, 'ABHA validation failed');
|
||||
$this->assertStringContainsString('ABHA Address does not exist or was not found in the ABDM registry', $result);
|
||||
}
|
||||
|
||||
public function testExtractBridgeErrorTextPreservesGenericWhenNoFieldErrors(): void
|
||||
{
|
||||
$payload = [
|
||||
|
|
@ -101,3 +113,4 @@ final class AbhaOtpErrorHandlingTest extends CIUnitTestCase
|
|||
$this->assertSame('ABDM gateway returned an error.', $result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user