Skip to content

Commit

Permalink
feat: customErros added of proxy response (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiagoGaonaC committed Oct 7, 2023
1 parent 8de9955 commit 3c81613
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ class AuthDataSourceImpl extends AuthDataSource {
@override
Future<User> login(String username, String password) async {
try {
final responde = await dio
.post('/auth/login', data: {'username': username, 'password': password});
final responde = await dio.post('/auth/login',
data: {'username': username, 'password': password});
final user = UserMapper.userJsonToEntity(responde.data);
return user;
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
throw CustomError(e.response?.data['message'] ?? 'Credentials wrong');
throw CustomError(
/*e.response?.data ?? */
'Username or Password wrong');
}
if (e.type == DioExceptionType.connectionTimeout) {
throw CustomError('Review your internet connection');
Expand All @@ -55,9 +57,10 @@ class AuthDataSourceImpl extends AuthDataSource {
final user = UserMapper.userJsonToEntity(responde.data);
return user;
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
if (e.response?.statusCode == 409) {
throw CustomError(
e.response?.data['message'] ?? 'Username already registered');
/*e.response?.data['message'] ?? */
'Username already registered');
}
if (e.type == DioExceptionType.connectionTimeout) {
throw CustomError('Review your internet connection');
Expand Down
14 changes: 6 additions & 8 deletions lib/features/auth/infrastructure/errors/auth_errors.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
class WrongCredentials implements Exception {

}

class InvalidToken implements Exception {

final String message;

WrongCredentials(this.message);
}

class ConectionTimeout implements Exception {
class InvalidToken implements Exception {}

}
class ConectionTimeout implements Exception {}

class CustomError implements Exception {
final String message;
Expand All @@ -19,4 +17,4 @@ class CustomError implements Exception {
CustomError(this.message, [this.loggedRequired = false]);
*/
CustomError(this.message);
}
}

0 comments on commit 3c81613

Please sign in to comment.