Skip to content

Commit

Permalink
#33: Added localized key support for network errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Apr 8, 2021
1 parent 808c364 commit 18b1125
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
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
9 changes: 5 additions & 4 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 All @@ -19,10 +22,7 @@ void main() {
setUp(() {
source = DioError(
requestOptions: RequestOptions(path: '/'),
response: Response(
requestOptions: RequestOptions(path: '/'),
statusCode: 404,
statusMessage: "Not found"),
response: Response(requestOptions: RequestOptions(path: '/'), statusCode: 404, statusMessage: "Not found"),
error: ArgumentError('Test'),
type: DioErrorType.other,
);
Expand All @@ -39,6 +39,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 18b1125

Please sign in to comment.