feat: enhance API error handling and response structure; introduce ApiException for V2 error codes

This commit is contained in:
Achintha Isuru
2026-03-17 14:15:26 -04:00
parent d6ddb7829e
commit b6a655a261
5 changed files with 116 additions and 52 deletions

View File

@@ -55,20 +55,6 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
final Map<String, dynamic> body =
response.data as Map<String, dynamic>;
// Check for V2 error responses.
if (response.code != '200' && response.code != '201') {
final String errorCode = body['code']?.toString() ?? response.code;
if (errorCode == 'INVALID_CREDENTIALS' ||
response.message.contains('INVALID_LOGIN_CREDENTIALS')) {
throw InvalidCredentialsException(
technicalMessage: response.message,
);
}
throw SignInFailedException(
technicalMessage: '$errorCode: ${response.message}',
);
}
// Step 2: Sign in locally so AuthInterceptor can attach Bearer tokens
// to subsequent requests. The V2 API already validated credentials, so
// email/password sign-in establishes the local Firebase Auth state.
@@ -115,12 +101,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
},
);
// Check for V2 error responses.
final Map<String, dynamic> body = response.data as Map<String, dynamic>;
if (response.code != '201' && response.code != '200') {
final String errorCode = body['code']?.toString() ?? response.code;
_throwSignUpError(errorCode, response.message);
}
// Step 2: Sign in locally to Firebase Auth so AuthInterceptor works
// for subsequent requests. The V2 API already created the Firebase