Geschlecht und Merkmal

This commit is contained in:
2025-10-21 23:30:50 +02:00
parent 31afb2f342
commit c084347fbd
6 changed files with 337 additions and 240 deletions
+3 -6
View File
@@ -1,12 +1,11 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
/// Lightweight API-Client mit einfachem 401-Retry via Refresh-Token.
class ApiClient {
ApiClient(
this.baseUrl, {
this.getAccessToken,
this.onUnauthorized, // z.B. () => tokenStorage.refreshAccess()
this.onUnauthorized,
});
final String baseUrl; // z.B. https://api.windesign.at/hedgehogs.php?r=
@@ -38,9 +37,8 @@ class ApiClient {
Future<T> _requestWithRetry<T>(String method, String path,
{Object? body}) async {
http.Response res = await _send(method, path, body: body);
var res = await _send(method, path, body: body);
// Bei 401 einmal Refresh versuchen
if (res.statusCode == 401 && onUnauthorized != null) {
await onUnauthorized!.call();
res = await _send(method, path, body: body);
@@ -49,9 +47,8 @@ class ApiClient {
if (res.statusCode >= 200 && res.statusCode < 300) {
if (res.body.isEmpty) return (null as T);
final decoded = jsonDecode(res.body);
return decoded as T; // Aufrufer achtet auf Typ (Map/List)
return decoded as T;
}
throw ApiException(res.statusCode, res.body);
}