feat(catalog): Katalogsuche in der App (KAT-01, 3b App) #63
2 changed files with 12 additions and 1 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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>(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue