Skip to content

Commit

Permalink
Merge pull request #34 from icapps/feature/#33-localized-error
Browse files Browse the repository at this point in the history
#33: Added localized key support for network errors
  • Loading branch information
NicolaVerbeeck authored Apr 8, 2021
2 parents 808c364 + 0ef76c0 commit cf0eb8c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
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

0 comments on commit cf0eb8c

Please sign in to comment.