feat(catalog): Katalogsuche in der App (KAT-01, 3b App) #63

Merged
cschlaefke merged 9 commits from feature/3b-katalog-suche-app into main 2026-11-04 17:29:11 +00:00
2 changed files with 12 additions and 1 deletions
Showing only changes of commit 668fdf1705 - Show all commits

View file

@ -5,6 +5,8 @@ import 'package:shuffle/core/platform/io_error.dart';
import 'package:shuffle/features/catalog/domain/catalog_failure.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
const _invalidInputCodes = {'P0001', '22003', '22P02'};
/// Translates exceptions of `supabase_flutter` into a [CatalogFailure]
/// (Spec #3 § 5.2).
CatalogFailure mapCatalogError(Object error) {
@ -13,7 +15,9 @@ CatalogFailure mapCatalogError(Object error) {
isIoNetworkError(error)) {
return const CatalogFailure.network();
}
if (error is PostgrestException && error.code == 'P0001') {
// P0001: RPC input checks; 22003: number out of range (smallint cast);
// 22P02: invalid text representation. None gets better by repeating.
if (error is PostgrestException && _invalidInputCodes.contains(error.code)) {
return const CatalogFailure.invalidInput();
}
return const CatalogFailure.unexpected();

View file

@ -182,6 +182,13 @@ void main() {
),
isA<CatalogInvalidInputFailure>(),
);
for (final code in ['22003', '22P02']) {
expect(
mapCatalogError(PostgrestException(message: 'x', code: code)),
isA<CatalogInvalidInputFailure>(),
reason: code,
);
}
expect(
mapCatalogError(const PostgrestException(message: 'x', code: '42501')),
isA<CatalogUnexpectedFailure>(),