fix(catalog): map 22003 and 22P02 to invalidInput
All checks were successful
All checks were successful
Refs #3 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
25212929ce
commit
668fdf1705
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:shuffle/features/catalog/domain/catalog_failure.dart';
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
|
||||||
|
const _invalidInputCodes = {'P0001', '22003', '22P02'};
|
||||||
|
|
||||||
/// Translates exceptions of `supabase_flutter` into a [CatalogFailure]
|
/// Translates exceptions of `supabase_flutter` into a [CatalogFailure]
|
||||||
/// (Spec #3 § 5.2).
|
/// (Spec #3 § 5.2).
|
||||||
CatalogFailure mapCatalogError(Object error) {
|
CatalogFailure mapCatalogError(Object error) {
|
||||||
|
|
@ -13,7 +15,9 @@ CatalogFailure mapCatalogError(Object error) {
|
||||||
isIoNetworkError(error)) {
|
isIoNetworkError(error)) {
|
||||||
return const CatalogFailure.network();
|
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.invalidInput();
|
||||||
}
|
}
|
||||||
return const CatalogFailure.unexpected();
|
return const CatalogFailure.unexpected();
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,13 @@ void main() {
|
||||||
),
|
),
|
||||||
isA<CatalogInvalidInputFailure>(),
|
isA<CatalogInvalidInputFailure>(),
|
||||||
);
|
);
|
||||||
|
for (final code in ['22003', '22P02']) {
|
||||||
|
expect(
|
||||||
|
mapCatalogError(PostgrestException(message: 'x', code: code)),
|
||||||
|
isA<CatalogInvalidInputFailure>(),
|
||||||
|
reason: code,
|
||||||
|
);
|
||||||
|
}
|
||||||
expect(
|
expect(
|
||||||
mapCatalogError(const PostgrestException(message: 'x', code: '42501')),
|
mapCatalogError(const PostgrestException(message: 'x', code: '42501')),
|
||||||
isA<CatalogUnexpectedFailure>(),
|
isA<CatalogUnexpectedFailure>(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue