Skip to content

Commit 1b8616a

Browse files
committed
refactor(auth): improve exception handling in initiateEmailSignIn
Refactors the try-catch block in the `initiateEmailSignIn` method to improve robustness and clarity. - The generic `catch` block now includes the stack trace in the log for better error diagnostics. - Adds a comment to the `on HtHttpException` block to clarify that it correctly propagates specific exceptions like `ForbiddenException`, preventing them from being masked as generic 50
1 parent deb906e commit 1b8616a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/src/services/auth_service.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ class AuthService {
105105
await _emailRepository.sendOtpEmail(recipientEmail: email, otpCode: code);
106106
_log.info('Initiated email sign-in for $email, code sent.');
107107
} on HtHttpException {
108-
// Propagate known exceptions from dependencies
108+
// Propagate known exceptions from dependencies or from this method's logic.
109+
// This ensures that specific errors like ForbiddenException are not
110+
// masked as a generic server error.
109111
rethrow;
110-
} catch (e) {
111-
// Catch unexpected errors during orchestration
112-
_log.severe('Error during initiateEmailSignIn for $email: $e');
112+
} catch (e, s) {
113+
// Catch unexpected errors during orchestration.
114+
_log.severe('Error during initiateEmailSignIn for $email: $e', e, s);
113115
throw const OperationFailedException(
114116
'Failed to initiate email sign-in process.',
115117
);

0 commit comments

Comments
 (0)