Files
minstrel/flutter_client/lib/api/error_copy.dart
T
bvandeusen c93b852e65 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).
2026-05-02 17:15:55 -04:00

23 lines
643 B
Dart

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.';
}