-
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.
Clean up error generation using extensions
- Loading branch information
Showing
7 changed files
with
77 additions
and
87 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:dio/dio.dart'; | ||
|
||
extension ErrorSegregation on Exception { | ||
AppError segregate() { | ||
if (this is AppError) { | ||
return this as AppError; | ||
} else if (this is DioError) { | ||
final error = this as DioError; | ||
return HttpError( | ||
message: error.response.toString(), | ||
stackTrace: error.stackTrace.toString(), | ||
); | ||
} else { | ||
return GeneralError(message: toString(), stackTrace: 'No stacktrace'); | ||
} | ||
} | ||
} | ||
|
||
sealed class AppError implements Exception { | ||
String get message; | ||
String get stackTrace; | ||
} | ||
|
||
class HttpError implements AppError { | ||
@override | ||
final String message; | ||
|
||
@override | ||
final String stackTrace; | ||
|
||
HttpError({required this.message, required this.stackTrace}); | ||
} | ||
|
||
class GeneralError implements AppError { | ||
@override | ||
final String message; | ||
|
||
@override | ||
final String stackTrace; | ||
|
||
GeneralError({required this.message, required this.stackTrace}); | ||
} |
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 was deleted.
Oops, something went wrong.
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