-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
34c9f4b
commit 2cef774
Showing
108 changed files
with
1,287 additions
and
1,653 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
"prefs", | ||
"riverpod", | ||
"screenutil", | ||
"unfocus", | ||
"usecase", | ||
"usecases" | ||
] | ||
} |
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 |
---|---|---|
|
@@ -33,3 +33,4 @@ analyzer: | |
- "**/*.freezed.dart" | ||
errors: | ||
invalid_annotation_target: ignore | ||
must_be_immutable: ignore |
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,121 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
|
||
import 'package:dio/dio.dart'; | ||
|
||
import 'package:base_flutter/data/remote/response/error_response.dart'; | ||
|
||
enum AppErrorType { | ||
network, | ||
badRequest, | ||
unauthorized, | ||
notFound, | ||
cancel, | ||
timeout, | ||
server, | ||
unknown, | ||
} | ||
|
||
class AppError { | ||
final String? message; | ||
final AppErrorType type; | ||
|
||
final int? errorCode; | ||
final List<ErrorResponse>? errors; | ||
|
||
AppError(this.type, this.message, {this.errorCode, this.errors}); | ||
|
||
factory AppError.from(Object? exception) { | ||
var type = AppErrorType.unknown; | ||
String? message = ''; | ||
int? code; | ||
List<ErrorResponse>? errs; | ||
if (exception is DioException) { | ||
message = exception.error.toString(); | ||
code = exception.response?.statusCode ?? -1; | ||
|
||
switch (exception.type) { | ||
case DioExceptionType.connectionTimeout: | ||
case DioExceptionType.receiveTimeout: | ||
type = AppErrorType.timeout; | ||
break; | ||
case DioExceptionType.sendTimeout: | ||
case DioExceptionType.connectionError: | ||
type = AppErrorType.network; | ||
break; | ||
case DioExceptionType.badResponse: | ||
switch (exception.response?.statusCode) { | ||
case HttpStatus.unauthorized: | ||
type = AppErrorType.unauthorized; | ||
break; | ||
case HttpStatus.badRequest: | ||
case HttpStatus.notFound: | ||
case HttpStatus.methodNotAllowed: | ||
case HttpStatus.unprocessableEntity: | ||
case HttpStatus.internalServerError: | ||
case HttpStatus.badGateway: | ||
case HttpStatus.serviceUnavailable: | ||
case HttpStatus.gatewayTimeout: | ||
type = AppErrorType.server; | ||
try { | ||
final serverErr = | ||
ErrorResponse.fromJson(exception.response?.data); | ||
errs = [serverErr]; | ||
} catch (ex) { | ||
errs = [ErrorResponse(statusCode: -1, message: ex.toString())]; | ||
} | ||
break; | ||
default: | ||
type = AppErrorType.unknown; | ||
break; | ||
} | ||
break; | ||
case DioExceptionType.cancel: | ||
type = AppErrorType.cancel; | ||
break; | ||
|
||
case DioExceptionType.unknown: | ||
default: | ||
if (exception.error is SocketException) { | ||
type = AppErrorType.network; | ||
} else { | ||
type = AppErrorType.unknown; | ||
} | ||
break; | ||
} | ||
} else if (exception is AuthenticationException) { | ||
type = AppErrorType.unauthorized; | ||
code = HttpStatus.unauthorized; | ||
message = exception.message; | ||
} else { | ||
code = -1; | ||
type = AppErrorType.unknown; | ||
message = 'AppError: $exception'; | ||
} | ||
|
||
return AppError(type, message, errorCode: code, errors: errs); | ||
} | ||
|
||
@override | ||
bool operator ==(covariant AppError other) { | ||
if (identical(this, other)) return true; | ||
|
||
return other.message == message && | ||
other.type == type && | ||
other.errorCode == errorCode && | ||
listEquals(other.errors, errors); | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'AppError(message: $message, type: $type, errorCode: $errorCode, errors: $errors)'; | ||
} | ||
} | ||
|
||
class AuthenticationException extends Object { | ||
AuthenticationException({ | ||
required this.message, | ||
}); | ||
final String message; | ||
} |
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:base_flutter/data/app_error.dart'; | ||
|
||
mixin DataSource { | ||
Future<T> excuse<T>(Future<T> Function() block) async { | ||
try { | ||
return await block(); | ||
} catch (e) { | ||
throw AppError.from(e); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
142 changes: 0 additions & 142 deletions
142
lib/data/data_sources/remote/api/client/res_api_client.dart
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
lib/data/data_sources/remote/api/exception/base/app_exception.dart
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
lib/data/data_sources/remote/api/exception/base/app_exception_wrapper.dart
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
lib/data/data_sources/remote/api/exception/base/exception_mapper.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.