added support for simultan downloads in files and talk, support for background downloads, enhanced loading in files with retry
This commit is contained in:
@@ -8,7 +8,9 @@ import 'package:marianum_mobile/api/api_error.dart';
|
||||
import 'package:marianum_mobile/api/errors/auth_exception.dart';
|
||||
import 'package:marianum_mobile/api/errors/error_mapper.dart';
|
||||
import 'package:marianum_mobile/api/errors/network_exception.dart';
|
||||
import 'package:marianum_mobile/api/errors/not_found_exception.dart';
|
||||
import 'package:marianum_mobile/api/errors/parse_exception.dart';
|
||||
import 'package:nextcloud/nextcloud.dart';
|
||||
|
||||
void main() {
|
||||
group('errorToUserMessage', () {
|
||||
@@ -95,7 +97,7 @@ void main() {
|
||||
expect(errorToUserMessage(ex), const NetworkException().userMessage);
|
||||
});
|
||||
|
||||
test('DioException badResponse maps to a server status message', () {
|
||||
test('DioException badResponse maps to the server error message', () {
|
||||
final ex = DioException(
|
||||
requestOptions: RequestOptions(path: '/x'),
|
||||
type: DioExceptionType.badResponse,
|
||||
@@ -104,7 +106,65 @@ void main() {
|
||||
statusCode: 503,
|
||||
),
|
||||
);
|
||||
expect(errorToUserMessage(ex), contains('503'));
|
||||
// The status code lives in the technical details, not the message.
|
||||
expect(
|
||||
errorToUserMessage(ex),
|
||||
contains('konnte die Anfrage gerade nicht verarbeiten'),
|
||||
);
|
||||
expect(errorToTechnicalDetails(ex), contains('503'));
|
||||
});
|
||||
});
|
||||
|
||||
group('DynamiteApiException mapping', () {
|
||||
test('500 maps to the server error message without the raw dump', () {
|
||||
const ex = DynamiteApiException(500, {'server': 'nginx'}, '');
|
||||
expect(
|
||||
errorToUserMessage(ex),
|
||||
contains('konnte die Anfrage gerade nicht verarbeiten'),
|
||||
);
|
||||
expect(errorToTechnicalDetails(ex), 'HTTP 500');
|
||||
expect(errorToTechnicalDetails(ex), isNot(contains('nginx')));
|
||||
expect(errorAllowsRetry(ex), isTrue);
|
||||
});
|
||||
|
||||
test('5xx details include a trimmed body preview', () {
|
||||
const ex = DynamiteApiException(503, {}, ' Service\n Unavailable ');
|
||||
expect(errorToTechnicalDetails(ex), 'HTTP 503 body=Service Unavailable');
|
||||
});
|
||||
|
||||
test('long bodies are capped in the details', () {
|
||||
final ex = DynamiteApiException(502, const {}, 'x' * 600);
|
||||
final details = errorToTechnicalDetails(ex)!;
|
||||
expect(details, startsWith('HTTP 502 body='));
|
||||
expect(details, endsWith('…'));
|
||||
expect(details.length, lessThan(600));
|
||||
});
|
||||
|
||||
test('401 maps to the unauthorized AuthException', () {
|
||||
const ex = DynamiteApiException(401, {}, '');
|
||||
expect(
|
||||
errorToUserMessage(ex),
|
||||
AuthException.unauthorized().userMessage,
|
||||
);
|
||||
expect(errorAllowsRetry(ex), isFalse);
|
||||
});
|
||||
|
||||
test('403 maps to the forbidden AuthException', () {
|
||||
const ex = DynamiteApiException(403, {}, '');
|
||||
expect(errorToUserMessage(ex), AuthException.forbidden().userMessage);
|
||||
expect(errorAllowsRetry(ex), isFalse);
|
||||
});
|
||||
|
||||
test('404 maps to NotFoundException', () {
|
||||
const ex = DynamiteApiException(404, {}, '');
|
||||
expect(errorToUserMessage(ex), const NotFoundException().userMessage);
|
||||
expect(errorAllowsRetry(ex), isFalse);
|
||||
});
|
||||
|
||||
test('429 maps to a rate-limit message that allows retry', () {
|
||||
const ex = DynamiteApiException(429, {}, '');
|
||||
expect(errorToUserMessage(ex), contains('Zu viele Anfragen'));
|
||||
expect(errorAllowsRetry(ex), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user