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),
|
||||
};
|
||||
} catch (error) {
|
||||
// Handle "Not Found" specifically — this is expected for discovery
|
||||
if (
|
||||
error instanceof NotFoundException ||
|
||||
(error instanceof Error && error.message.toLowerCase().includes("not found"))
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 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"
|
||||
// Sub-account lookup is best-effort — many WHMCS setups don't expose GetUsers.
|
||||
// Log and return null rather than blocking the flow. The primary client lookup
|
||||
// (findClientByEmail) is the authority; this is supplementary.
|
||||
this.logger.warn(
|
||||
{ email, error: extractErrorMessage(error) },
|
||||
"User sub-account lookup unavailable — skipping"
|
||||
);
|
||||
throw error;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +146,6 @@ export class WhmcsAccountDiscoveryService {
|
||||
// If no client found, check for a user (sub-account)
|
||||
const user = await this.findUserByEmail(email);
|
||||
if (user) {
|
||||
// User found - fetch the associated client
|
||||
return this.getClientDetailsById(user.clientId);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user