mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-14 02:10:58 +01:00
firebase_auth_rest.dart 333 -> 238 + firebase_credentials 71
+ firebase_auth_error 31
firebase_client.dart 283 -> 207 + firebase_keys 60 + firebase_errors 19
sync.dart 259 -> 141 + sync_state 121
Mirrors the split just made on the Python side, module for module, so the two
implementations stay legible against each other: credentials with their store,
key escaping with its escape table, the error type with the response parser
that builds its message.
Every new file is added to lib/crdt_sync.dart. A src/ file that is not in the
barrel compiles and tests green while silently dropping the symbol from every
consumer's import, so the export list is part of the split, not an afterthought.
280 tests pass and `dart analyze` is clean — including the four consumers
(firebase_config, secure_credential_store) whose imports had to follow the
moved types.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CFSGeWxHPY5rHUGrPqhcmG
32 lines
1.0 KiB
Dart
32 lines
1.0 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'remote_store.dart';
|
|
|
|
/// Raised for an authentication failure the caller must not silently ignore.
|
|
///
|
|
/// A [RemoteSyncError] so callers that only care about "sync is broken" can
|
|
/// catch one type, while a settings screen can single this out to say
|
|
/// "your password is wrong" rather than "the network is down".
|
|
class FirebaseAuthError extends RemoteSyncError {
|
|
FirebaseAuthError(super.message);
|
|
}
|
|
|
|
/// The human-readable reason buried in an identitytoolkit error body.
|
|
///
|
|
/// Returns an empty string for a non-JSON body (a proxy error page, say),
|
|
/// where the status code is all the detail there is.
|
|
String reasonFrom(String body) {
|
|
try {
|
|
final decoded = jsonDecode(body);
|
|
if (decoded is Map<String, dynamic>) {
|
|
final error = decoded['error'];
|
|
if (error is Map<String, dynamic>) return '(${error['message']})';
|
|
if (error is String) return '($error)';
|
|
}
|
|
} on FormatException {
|
|
// Non-JSON body (a proxy error page, say): the status code is all the
|
|
// detail there is.
|
|
}
|
|
return '';
|
|
}
|