feat(flutter/api): dio client with Bearer interceptor + ApiError
ApiError.fromDio handles both server envelope shapes: {"error":"code"}
(admin endpoints) and {"error":{"code","message"}} (most others). Same
dual-shape problem the web apiFetch already solves. Token comes from a
resolver function so the auth provider can swap implementations
without touching the client.
ErrorCopy is a lazy singleton over assets/error-copy.json with the
same fallback chain web uses (specific code -> unknown -> hard-coded).
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
|
||||
class ErrorCopy {
|
||||
ErrorCopy._(this._table);
|
||||
final Map<String, String> _table;
|
||||
|
||||
static ErrorCopy? _instance;
|
||||
|
||||
static Future<ErrorCopy> load() async {
|
||||
if (_instance != null) return _instance!;
|
||||
final raw = await rootBundle.loadString('assets/error-copy.json');
|
||||
final m = (jsonDecode(raw) as Map).cast<String, dynamic>().map(
|
||||
(k, v) => MapEntry(k, v.toString()),
|
||||
);
|
||||
_instance = ErrorCopy._(m);
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
String forCode(String code) =>
|
||||
_table[code] ?? _table['unknown'] ?? 'Something went wrong.';
|
||||
}
|
||||
Reference in New Issue
Block a user