Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [0.4.7] - 2026-04-27

* 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

* Added `maintenanceError` and `serviceDownError` error codes to `GlobalErrorCode`.
Expand Down
19 changes: 14 additions & 5 deletions lib/src/error_result_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) ??
Expand Down Expand Up @@ -65,19 +71,22 @@ extension CommonErrorResultExtensionErrorCode on ErrorResult? {

/// Расширения [ErrorResult] для работы с кодами общих ошибок.
extension InternalErrorCodeExtensionErrorResult on ErrorResult {
static List<int> get _temporaryServerStatuses => [
HttpStatus.badGateway,
static const _temporaryServerStatuses = {
HttpStatus.serviceUnavailable,
HttpStatus.gatewayTimeout,
];
};

/// Определяет, является ли текущий результат ошибкой взаимодействия с внешними сервисами.
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]) =>
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
95 changes: 95 additions & 0 deletions test/error_result_extension_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
() {
Expand Down Expand Up @@ -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);
Expand Down
Loading