-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling #13
Merged
Merged
Error handling #13
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d6a7930
implement match detail view
cp-sidhdhi-p bf0e9e8
Merge branch 'main' into sidhdhi/implement-match-detail-tab
cp-sidhdhi-p 264547e
localization
cp-sidhdhi-p 4eacd12
redesign home screen running matches cell
cp-sidhdhi-p 46a449f
remove match detail state screen
cp-sidhdhi-p 90a6156
error handling
cp-sidhdhi-p bd72e51
Merge branch 'main' into sidhdhi/refactor-string-error-handling
cp-sidhdhi-p 492ac58
rebase conflict
cp-sidhdhi-p c40d1ab
change otp textfield
cp-sidhdhi-p 2b1b882
fix running match stat not updated
cp-sidhdhi-p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'dart:io'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:data/errors/app_error_l10n_codes.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
|
||
import '../utils/constant/firebase_error_constant.dart'; | ||
|
||
class AppError implements Exception { | ||
final String? message; | ||
final String? l10nCode; | ||
final String? statusCode; | ||
final StackTrace? stackTrace; | ||
|
||
const AppError({ | ||
this.message, | ||
this.statusCode, | ||
this.l10nCode, | ||
this.stackTrace, | ||
}); | ||
|
||
@override | ||
String toString() { | ||
return '$runtimeType{message: $message, code: $statusCode, l10nCode: $l10nCode, stackTrace: $stackTrace}'; | ||
} | ||
|
||
factory AppError.fromError(Object error, [StackTrace? stack]) { | ||
if (error is AppError) { | ||
return error; | ||
} else if (error is SocketException) { | ||
return const NoConnectionError(); | ||
} else if (error is FirebaseException) { | ||
return _handleFirebaseError(error); | ||
} else if (error is TypeError) { | ||
return SomethingWentWrongError(stackTrace: error.stackTrace); | ||
} else { | ||
return SomethingWentWrongError(stackTrace: stack); | ||
} | ||
} | ||
|
||
static AppError _handleFirebaseError(FirebaseException error) { | ||
switch (error.code) { | ||
case errorInvalidVerificationCode: | ||
return AppError( | ||
statusCode: error.code, | ||
message: error.message, | ||
l10nCode: AppErrorL10nCodes.invalidVerificationCode, | ||
stackTrace: error.stackTrace); | ||
case errorInvalidPhoneNumber: | ||
return AppError( | ||
statusCode: error.code, | ||
message: error.message, | ||
l10nCode: AppErrorL10nCodes.invalidPhoneNumber, | ||
stackTrace: error.stackTrace); | ||
case errorNetworkRequestFailed: | ||
return const NoConnectionError(); | ||
default: | ||
return SomethingWentWrongError( | ||
statusCode: error.code, | ||
message: error.message, | ||
stackTrace: error.stackTrace); | ||
} | ||
} | ||
} | ||
|
||
class NoConnectionError extends AppError { | ||
const NoConnectionError() | ||
: super( | ||
l10nCode: AppErrorL10nCodes.noInternetConnection, | ||
message: | ||
"No internet connection. Please check your network and try again."); | ||
} | ||
|
||
class SomethingWentWrongError extends AppError { | ||
const SomethingWentWrongError({ | ||
super.message, | ||
super.statusCode, | ||
super.stackTrace, | ||
}) : super(l10nCode: AppErrorL10nCodes.somethingWentWrongError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AppErrorL10nCodes { | ||
static const noInternetConnection = 'no-internet-connection'; | ||
static const somethingWentWrongError = 'something-went-wrong'; | ||
static const invalidVerificationCode = 'invalid-verification-code'; | ||
static const invalidPhoneNumber = 'invalid-phone-number'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure comprehensive error handling in
verifyPhoneNumber
.The method
verifyPhoneNumber
uses a try-catch block to handle errors, which is good. However, ensure that all potential exceptions, especially those specific to phone number verification, are adequately handled and logged.