-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
179 additions
and
27 deletions.
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
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,50 @@ | ||
import 'package:ecommerce_app/src/localization/string_hardcoded.dart'; | ||
|
||
/// Base class for all all client-side errors that can be generated by the app | ||
sealed class AppException implements Exception { | ||
AppException(this.code, this.message); | ||
final String code; | ||
final String message; | ||
} | ||
|
||
/// Auth | ||
class EmailAlreadyInUseException extends AppException { | ||
EmailAlreadyInUseException() | ||
: super('email-already-in-use', 'Email already in use'.hardcoded); | ||
} | ||
|
||
class WeakPasswordException extends AppException { | ||
WeakPasswordException() | ||
: super('weak-password', 'Password is too weak'.hardcoded); | ||
} | ||
|
||
class WrongPasswordException extends AppException { | ||
WrongPasswordException() | ||
: super('wrong-password', 'Wrong password'.hardcoded); | ||
} | ||
|
||
class UserNotFoundException extends AppException { | ||
UserNotFoundException() : super('user-not-found', 'User not found'.hardcoded); | ||
} | ||
|
||
/// Cart | ||
class CartSyncFailedException extends AppException { | ||
CartSyncFailedException() | ||
: super('cart-sync-failed', | ||
'An error has occurred while updating the shopping cart'.hardcoded); | ||
} | ||
|
||
/// Checkout | ||
class PaymentFailureEmptyCartException extends AppException { | ||
PaymentFailureEmptyCartException() | ||
: super('payment-failure-empty-cart', | ||
'Can\'t place an order if the cart is empty'.hardcoded); | ||
} | ||
|
||
/// Orders | ||
class ParseOrderFailureException extends AppException { | ||
ParseOrderFailureException(this.status) | ||
: super('parse-order-failure', | ||
'Could not parse order status: $status'.hardcoded); | ||
final String status; | ||
} |
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,51 @@ | ||
import 'package:ecommerce_app/src/localization/string_hardcoded.dart'; | ||
|
||
/// An exception type to represent all client-side errors that can be generated | ||
/// by the app | ||
enum AppExceptionEnum { | ||
// Auth | ||
emailAlreadyInUse('email-already-in-use'), | ||
weakPassword('weak-password'), | ||
wrongPassword('wrong-password'), | ||
userNotFound('user-not-found'), | ||
// Cart | ||
cartSyncFailed('cart-sync-failed'), | ||
// Checkout | ||
paymentFailureEmptyCart('payment-failure-empty-cart'), | ||
// Orders | ||
parseOrderFailure('parse-order-failure'); | ||
|
||
const AppExceptionEnum(this.code); | ||
|
||
/// A value that can be sent to the backend when logging the error | ||
final String code; | ||
|
||
/// A user-friendly message that can be shown in the UI. | ||
// * This needs to be a getter variable or a method since the error message | ||
// * can't be declared as const if it's localized | ||
String get message { | ||
switch (this) { | ||
// Auth | ||
case emailAlreadyInUse: | ||
return 'Email already in use'.hardcoded; | ||
case weakPassword: | ||
return 'Password is too weak'.hardcoded; | ||
case wrongPassword: | ||
return 'Wrong password'.hardcoded; | ||
case userNotFound: | ||
return 'User not found'.hardcoded; | ||
// Cart | ||
case cartSyncFailed: | ||
return 'An error has occurred while updating the shopping cart' | ||
.hardcoded; | ||
// Checkout | ||
case paymentFailureEmptyCart: | ||
return 'Can\'t place an order if the cart is empty'.hardcoded; | ||
// Orders | ||
case parseOrderFailure: | ||
return 'Could not parse order status'.hardcoded; | ||
default: | ||
return 'Unknown error'.hardcoded; | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
ecommerce_app/lib/src/features/authentication/domain/fake_app_user.dart
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,11 @@ | ||
import 'package:ecommerce_app/src/features/authentication/domain/app_user.dart'; | ||
|
||
/// Fake user class used to simulate a user account on the backend | ||
class FakeAppUser extends AppUser { | ||
FakeAppUser({ | ||
required super.uid, | ||
required super.email, | ||
required this.password, | ||
}); | ||
final String password; | ||
} |
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
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
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
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