From 18b1125f7af86592703d1fd893df0d24cfec0395 Mon Sep 17 00:00:00 2001 From: Koen Van Looveren Date: Thu, 8 Apr 2021 12:14:24 +0200 Subject: [PATCH] #33: Added localized key support for network errors --- lib/src/exception/localized_error.dart | 3 +++ lib/src/exception/network_error.dart | 3 ++- test/exception/network_error_test.dart | 9 +++++---- test/util/logging/logging_test.dart | 3 +++ 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 lib/src/exception/localized_error.dart diff --git a/lib/src/exception/localized_error.dart b/lib/src/exception/localized_error.dart new file mode 100644 index 0000000..f31d30c --- /dev/null +++ b/lib/src/exception/localized_error.dart @@ -0,0 +1,3 @@ +mixin LocalizedError { + String getLocalizedKey(); +} diff --git a/lib/src/exception/network_error.dart b/lib/src/exception/network_error.dart index 3bc3891..685f3f2 100644 --- a/lib/src/exception/network_error.dart +++ b/lib/src/exception/network_error.dart @@ -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}) diff --git a/test/exception/network_error_test.dart b/test/exception/network_error_test.dart index 587cb56..fff1520 100644 --- a/test/exception/network_error_test.dart +++ b/test/exception/network_error_test.dart @@ -11,6 +11,9 @@ class TestableNetworkError extends NetworkError { @override String? get getErrorCode => "Test"; + + @override + String getLocalizedKey() => 'testable_network_error'; } void main() { @@ -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, ); @@ -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'); }); }); } diff --git a/test/util/logging/logging_test.dart b/test/util/logging/logging_test.dart index 7b958bd..402fab7 100644 --- a/test/util/logging/logging_test.dart +++ b/test/util/logging/logging_test.dart @@ -9,6 +9,9 @@ class MockNetworkError extends NetworkError { @override String? get getErrorCode => throw UnimplementedError(); + + @override + String getLocalizedKey() => 'mock_network_error'; } void main() {