refactor: improve WHMCS account discovery error handling
- Simplify error handling in WhmcsAccountDiscoveryService by logging warnings for user sub-account lookup failures instead of throwing errors. - Ensure that the primary client lookup remains the authoritative source while allowing supplementary checks for user accounts. - Enhance code clarity and maintainability by removing unnecessary error checks.
This commit is contained in:
parent
9941250cb5
commit
1156398caa
@ -120,24 +120,14 @@ export class WhmcsAccountDiscoveryService {
|
|||||||
clientId: Number(clientAssociation.id),
|
clientId: Number(clientAssociation.id),
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Handle "Not Found" specifically — this is expected for discovery
|
// Sub-account lookup is best-effort — many WHMCS setups don't expose GetUsers.
|
||||||
if (
|
// Log and return null rather than blocking the flow. The primary client lookup
|
||||||
error instanceof NotFoundException ||
|
// (findClientByEmail) is the authority; this is supplementary.
|
||||||
(error instanceof Error && error.message.toLowerCase().includes("not found"))
|
this.logger.warn(
|
||||||
) {
|
{ email, error: extractErrorMessage(error) },
|
||||||
return null;
|
"User sub-account lookup unavailable — skipping"
|
||||||
}
|
|
||||||
|
|
||||||
// Re-throw all other errors (auth failures, network issues, timeouts, etc.)
|
|
||||||
// to avoid silently masking problems like 403 permission errors
|
|
||||||
this.logger.error(
|
|
||||||
{
|
|
||||||
email,
|
|
||||||
error: extractErrorMessage(error),
|
|
||||||
},
|
|
||||||
"Failed to discover user by email"
|
|
||||||
);
|
);
|
||||||
throw error;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +146,6 @@ export class WhmcsAccountDiscoveryService {
|
|||||||
// If no client found, check for a user (sub-account)
|
// If no client found, check for a user (sub-account)
|
||||||
const user = await this.findUserByEmail(email);
|
const user = await this.findUserByEmail(email);
|
||||||
if (user) {
|
if (user) {
|
||||||
// User found - fetch the associated client
|
|
||||||
return this.getClientDetailsById(user.clientId);
|
return this.getClientDetailsById(user.clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user