Skip to content
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

#33: Added localized key support for network errors #34

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/icapps_architecture.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library icapps_architecture;

export 'src/exception/localized_error.dart';
export 'src/exception/network_error.dart';
export 'src/extension/context_extensions.dart';
export 'src/extension/iterable_extensions.dart';
Expand Down
3 changes: 3 additions & 0 deletions lib/src/exception/localized_error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mixin LocalizedError {
String getLocalizedKey();
}
3 changes: 2 additions & 1 deletion lib/src/exception/network_error.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:dio/dio.dart';
import 'package:icapps_architecture/src/exception/localized_error.dart';

/// Base class for network errors
abstract class NetworkError extends DioError {
abstract class NetworkError extends DioError with LocalizedError {
final String? statusCodeValue;

NetworkError(DioError dioError, {this.statusCodeValue})
Expand Down
4 changes: 4 additions & 0 deletions test/exception/network_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class TestableNetworkError extends NetworkError {

@override
String? get getErrorCode => "Test";

@override
String getLocalizedKey() => 'testable_network_error';
}

void main() {
Expand Down Expand Up @@ -39,6 +42,7 @@ void main() {
expect(sut.response, source.response);
expect(sut.requestOptions, source.requestOptions);
expect(sut.type, source.type);
expect(sut.getLocalizedKey(), 'testable_network_error');
});
});
}
3 changes: 3 additions & 0 deletions test/util/logging/logging_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class MockNetworkError extends NetworkError {

@override
String? get getErrorCode => throw UnimplementedError();

@override
String getLocalizedKey() => 'mock_network_error';
}

void main() {
Expand Down