From 963083a76e9a7c23037452f393d955d2288f69bd Mon Sep 17 00:00:00 2001 From: SF97 Date: Sun, 26 Apr 2026 19:37:18 +0200 Subject: [PATCH 1/6] Add RemoteError getters and extensions --- CHANGELOG.md | 7 +++++++ lib/src/error_result_extension.dart | 12 ++++++++++++ lib/src/remote_error_extension.dart | 14 ++++++++++++++ pubspec.yaml | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f14f9a0..e01f84a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [0.4.7] - 2026-04-27 + +* Added `isMaintenanceError` and `shouldSuppressLogging` getters to `RemoteError` + and `ErrorResult` extensions. `shouldSuppressLogging` indicates that the error + should not be logged or shown to the user via a separate message (e.g. during + server maintenance). + ## [0.4.6] - 2026-04-02 * Added `maintenanceError` and `serviceDownError` error codes to `GlobalErrorCode`. diff --git a/lib/src/error_result_extension.dart b/lib/src/error_result_extension.dart index 5a7749a..9b36936 100644 --- a/lib/src/error_result_extension.dart +++ b/lib/src/error_result_extension.dart @@ -54,6 +54,18 @@ extension CommonErrorResultExtensionErrorCode on ErrorResult? { bool isValidationError([int? code]) => toError()?.isValidationError(code) ?? false; + /// Определяет, является ли ошибка сообщением о режиме обслуживания. + /// + /// См. [GlobalErrorCode.maintenanceError]. + bool get isMaintenanceError => + toError()?.isMaintenanceError ?? false; + + /// Определяет, следует ли подавить логирование данной ошибки. + /// + /// См. [CommonRemoteErrorExtensionErrorCode.shouldSuppressLogging]. + bool get shouldSuppressLogging => + toError()?.shouldSuppressLogging ?? false; + /// Возвращает [RemoteError] текущего результата. RemoteError? toError() => this?.error is RemoteError ? this!.error as RemoteError : null; diff --git a/lib/src/remote_error_extension.dart b/lib/src/remote_error_extension.dart index a4bd592..e27a325 100644 --- a/lib/src/remote_error_extension.dart +++ b/lib/src/remote_error_extension.dart @@ -19,6 +19,20 @@ extension CommonRemoteErrorExtensionErrorCode on RemoteError { /// Определяет, соответствует ли ошибка указанному коду [ValidationErrorCode] если указан. bool isValidationError([int? code]) => isError(ValidationErrorCode.domain, code); + + /// Определяет, является ли ошибка сообщением о режиме обслуживания. + /// + /// См. [GlobalErrorCode.maintenanceError]. + bool get isMaintenanceError => isGlobalError(GlobalErrorCode.maintenanceError); + + /// Определяет, следует ли подавить логирование данной ошибки. + /// + /// Возвращает `true` для ошибок, которые являются временным/ожидаемым + /// состоянием сервера (например, режим обслуживания) - такие ошибки + /// не должны попадать в логи и не должны инициировать показ отдельных + /// сообщений пользователю (за исключением случаев, когда пользователю + /// требуется показать результат запроса явно). + bool get shouldSuppressLogging => isMaintenanceError; } /// Расширения [RemoteError] для работы с кодами общих ошибок. diff --git a/pubspec.yaml b/pubspec.yaml index ef290a6..d99570a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: innim_remote_error description: Remote error object and common codes for Innim projects. Using Dio. -version: 0.4.6 +version: 0.4.7 homepage: https://github.com/innim/ repository: https://github.com/Innim/flutter_remote_error issue_tracker: https://github.com/Innim/flutter_remote_error/issues From a7c6c477af4fb86fb87d6228537f40b159c286b0 Mon Sep 17 00:00:00 2001 From: SF97 Date: Mon, 27 Apr 2026 16:57:15 +0200 Subject: [PATCH 2/6] code optimization --- lib/src/error_result_extension.dart | 27 ++++++++++++--------------- lib/src/remote_error_extension.dart | 14 -------------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/lib/src/error_result_extension.dart b/lib/src/error_result_extension.dart index 9b36936..5b28505 100644 --- a/lib/src/error_result_extension.dart +++ b/lib/src/error_result_extension.dart @@ -23,6 +23,12 @@ extension CommonErrorResultExtensionErrorCode on ErrorResult? { bool get isExternalServiceError => toError()?.isGlobalError(GlobalErrorCode.externalServiceError) ?? false; + /// Определяет, является ли ошибка сообщением о режиме обслуживания. + /// + /// См. [GlobalErrorCode.maintenanceError]. + bool get isMaintenanceError => + toError()?.isGlobalError(GlobalErrorCode.maintenanceError) ?? false; + /// Определяет, является ли текущий результат ошибкой сокет соединения. bool get isSocketConnectionFailed => toError()?.isNetworkError(NetworkErrorCode.socketConnectionFailed) ?? @@ -54,18 +60,6 @@ extension CommonErrorResultExtensionErrorCode on ErrorResult? { bool isValidationError([int? code]) => toError()?.isValidationError(code) ?? false; - /// Определяет, является ли ошибка сообщением о режиме обслуживания. - /// - /// См. [GlobalErrorCode.maintenanceError]. - bool get isMaintenanceError => - toError()?.isMaintenanceError ?? false; - - /// Определяет, следует ли подавить логирование данной ошибки. - /// - /// См. [CommonRemoteErrorExtensionErrorCode.shouldSuppressLogging]. - bool get shouldSuppressLogging => - toError()?.shouldSuppressLogging ?? false; - /// Возвращает [RemoteError] текущего результата. RemoteError? toError() => this?.error is RemoteError ? this!.error as RemoteError : null; @@ -78,7 +72,6 @@ extension CommonErrorResultExtensionErrorCode on ErrorResult? { /// Расширения [ErrorResult] для работы с кодами общих ошибок. extension InternalErrorCodeExtensionErrorResult on ErrorResult { static List get _temporaryServerStatuses => [ - HttpStatus.badGateway, HttpStatus.serviceUnavailable, HttpStatus.gatewayTimeout, ]; @@ -87,9 +80,13 @@ extension InternalErrorCodeExtensionErrorResult on ErrorResult { bool get isEmptyDataError => isInternalError(InternalErrorCode.emptyData); /// Определяет, является ли текущий результат временной ошибкой сервера. + /// + /// Включает в себя режим обслуживания (см. [isMaintenanceError]) - он + /// также считается временным состоянием сервера. bool get isTemporaryServerError => - toError()?.isInternalError(InternalErrorCode.temporaryServerError) ?? - _temporaryServerStatuses.contains(toDioError()?.response?.statusCode); + isMaintenanceError || + (toError()?.isInternalError(InternalErrorCode.temporaryServerError) ?? + _temporaryServerStatuses.contains(toDioError()?.response?.statusCode)); /// Определяет, соответствует ли ошибка указанному коду [InternalErrorCode] если указан. bool isInternalError([int? code]) => diff --git a/lib/src/remote_error_extension.dart b/lib/src/remote_error_extension.dart index e27a325..a4bd592 100644 --- a/lib/src/remote_error_extension.dart +++ b/lib/src/remote_error_extension.dart @@ -19,20 +19,6 @@ extension CommonRemoteErrorExtensionErrorCode on RemoteError { /// Определяет, соответствует ли ошибка указанному коду [ValidationErrorCode] если указан. bool isValidationError([int? code]) => isError(ValidationErrorCode.domain, code); - - /// Определяет, является ли ошибка сообщением о режиме обслуживания. - /// - /// См. [GlobalErrorCode.maintenanceError]. - bool get isMaintenanceError => isGlobalError(GlobalErrorCode.maintenanceError); - - /// Определяет, следует ли подавить логирование данной ошибки. - /// - /// Возвращает `true` для ошибок, которые являются временным/ожидаемым - /// состоянием сервера (например, режим обслуживания) - такие ошибки - /// не должны попадать в логи и не должны инициировать показ отдельных - /// сообщений пользователю (за исключением случаев, когда пользователю - /// требуется показать результат запроса явно). - bool get shouldSuppressLogging => isMaintenanceError; } /// Расширения [RemoteError] для работы с кодами общих ошибок. From 38bc3c55a86e0e6c15fdf7c6e515f147c88e8722 Mon Sep 17 00:00:00 2001 From: SF97 Date: Mon, 27 Apr 2026 16:57:27 +0200 Subject: [PATCH 3/6] add test --- test/error_result_extension_test.dart | 95 +++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/test/error_result_extension_test.dart b/test/error_result_extension_test.dart index c68f8e0..2995ecf 100644 --- a/test/error_result_extension_test.dart +++ b/test/error_result_extension_test.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:dio/dio.dart'; import 'package:innim_remote_error/innim_remote_error.dart'; import 'package:test/test.dart'; @@ -85,6 +87,47 @@ void main() { }); }); + group('isMaintenanceError', () { + test('should return true for GlobalErrorCode.maintenanceError', () { + final res = _remoteError( + GlobalErrorCode.domain, + GlobalErrorCode.maintenanceError, + ); + + expect(res.isMaintenanceError, isTrue); + }); + + test('should return false for other GlobalErrorCode code', () { + final res = _remoteError( + GlobalErrorCode.domain, + GlobalErrorCode.notFound, + ); + + expect(res.isMaintenanceError, isFalse); + }); + + test('should return false for non-matching domain', () { + final res = _remoteError( + 'other_domain', + GlobalErrorCode.maintenanceError, + ); + + expect(res.isMaintenanceError, isFalse); + }); + + test('should return false when no RemoteError', () { + final res = _dioError(statusCode: 500); + + expect(res.isMaintenanceError, isFalse); + }); + + test('should return false when called on null', () { + const ErrorResult? res = null; + + expect(res.isMaintenanceError, isFalse); + }); + }); + group('isSocketConnectionFailed', () { test('should return true for NetworkErrorCode.socketConnectionFailed', () { @@ -411,6 +454,58 @@ void main() { }); }); + group('InternalErrorCodeExtensionErrorResult', () { + group('isTemporaryServerError', () { + test('should return true for InternalErrorCode.temporaryServerError', () { + final res = _remoteError( + InternalErrorCode.domain, + InternalErrorCode.temporaryServerError, + ); + + expect(res.isTemporaryServerError, isTrue); + }); + + test('should return true for GlobalErrorCode.maintenanceError', () { + final res = _remoteError( + GlobalErrorCode.domain, + GlobalErrorCode.maintenanceError, + ); + + expect(res.isTemporaryServerError, isTrue); + }); + + test('should return true if http status is 503', () { + final res = _dioError(statusCode: HttpStatus.serviceUnavailable); + + expect(res.isTemporaryServerError, isTrue); + }); + + test('should return true if http status is 504', () { + final res = _dioError(statusCode: HttpStatus.gatewayTimeout); + + expect(res.isTemporaryServerError, isTrue); + }); + + test('should return false if http status is 502', () { + final res = _dioError(statusCode: HttpStatus.badGateway); + + expect(res.isTemporaryServerError, isFalse); + }); + + test('should return false if http status is 500', () { + final res = _dioError(statusCode: HttpStatus.internalServerError); + + expect(res.isTemporaryServerError, isFalse); + }); + + test('should return false for other RemoteError', () { + final res = _remoteError('other', 1); + + expect(res.isTemporaryServerError, isFalse); + }); + }); + }); + group('toError()', () { test('should return RemoteError when error is RemoteError', () { const remoteError = RemoteError('test_domain', 123); From 4361d16962e622c321eab56e417b07428c22fbdd Mon Sep 17 00:00:00 2001 From: SF97 Date: Mon, 27 Apr 2026 16:57:55 +0200 Subject: [PATCH 4/6] update changelog --- CHANGELOG.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e01f84a..ad6d7ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ ## [0.4.7] - 2026-04-27 -* Added `isMaintenanceError` and `shouldSuppressLogging` getters to `RemoteError` - and `ErrorResult` extensions. `shouldSuppressLogging` indicates that the error - should not be logged or shown to the user via a separate message (e.g. during - server maintenance). +* Added `isMaintenanceError` getter on `ErrorResult?` extension - returns `true` + for [GlobalErrorCode.maintenanceError]. +* `isTemporaryServerError` now also returns `true` for maintenance errors - + maintenance is treated as a temporary server state. +* `HttpStatus.badGateway` (502) is no longer included in + `isTemporaryServerError`. It was a fallback for maintenance handling; with + an explicit `maintenanceError` code, 502 should be reported separately. ## [0.4.6] - 2026-04-02 From f3d0a7de28f5739d0938273db4f1f856e77021bf Mon Sep 17 00:00:00 2001 From: greymag Date: Tue, 28 Apr 2026 08:13:45 +0200 Subject: [PATCH 5/6] docs: fix markdown Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6d7ef..cbb514e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## [0.4.7] - 2026-04-27 * Added `isMaintenanceError` getter on `ErrorResult?` extension - returns `true` - for [GlobalErrorCode.maintenanceError]. + for `GlobalErrorCode.maintenanceError`. * `isTemporaryServerError` now also returns `true` for maintenance errors - maintenance is treated as a temporary server state. * `HttpStatus.badGateway` (502) is no longer included in From 7dab8f83c8648389a78c97b86e935ce54199d491 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 06:15:41 +0000 Subject: [PATCH 6/6] change _temporaryServerStatuses to static const Set Agent-Logs-Url: https://github.com/Innim/flutter_remote_error/sessions/7776935b-ad64-4475-ad47-9c6feb1993b7 Co-authored-by: greymag <1502131+greymag@users.noreply.github.com> --- lib/src/error_result_extension.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/error_result_extension.dart b/lib/src/error_result_extension.dart index 5b28505..ad067eb 100644 --- a/lib/src/error_result_extension.dart +++ b/lib/src/error_result_extension.dart @@ -71,10 +71,10 @@ extension CommonErrorResultExtensionErrorCode on ErrorResult? { /// Расширения [ErrorResult] для работы с кодами общих ошибок. extension InternalErrorCodeExtensionErrorResult on ErrorResult { - static List get _temporaryServerStatuses => [ + static const _temporaryServerStatuses = { HttpStatus.serviceUnavailable, HttpStatus.gatewayTimeout, - ]; + }; /// Определяет, является ли текущий результат ошибкой взаимодействия с внешними сервисами. bool get isEmptyDataError => isInternalError(InternalErrorCode.emptyData);