fix: add 30s timeout to API calls and catchError fallback on schedule load
Without a timeout, a hanging backend request left the schedule page showing an infinite spinner forever. Timeout ensures any hung request fails fast and the spinner resolves. The catchError fallback in schedule_view handles the edge case where getProfessional rejects unexpectedly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
dbeda22e19
commit
360f88777b
@@ -30,8 +30,10 @@ class ApiService {
|
||||
throw Exception(body['message'] ?? 'Error ${res.statusCode}');
|
||||
}
|
||||
|
||||
static const _timeout = Duration(seconds: 30);
|
||||
|
||||
Future<dynamic> get(String path) async {
|
||||
final res = await http.get(Uri.parse('$baseUrl$path'), headers: await _headers());
|
||||
final res = await http.get(Uri.parse('$baseUrl$path'), headers: await _headers()).timeout(_timeout);
|
||||
return _parse(res);
|
||||
}
|
||||
|
||||
@@ -40,7 +42,7 @@ class ApiService {
|
||||
Uri.parse('$baseUrl$path'),
|
||||
headers: await _headers(),
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
).timeout(_timeout);
|
||||
return _parse(res);
|
||||
}
|
||||
|
||||
@@ -49,12 +51,12 @@ class ApiService {
|
||||
Uri.parse('$baseUrl$path'),
|
||||
headers: await _headers(),
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
).timeout(_timeout);
|
||||
return _parse(res);
|
||||
}
|
||||
|
||||
Future<dynamic> delete(String path) async {
|
||||
final res = await http.delete(Uri.parse('$baseUrl$path'), headers: await _headers());
|
||||
final res = await http.delete(Uri.parse('$baseUrl$path'), headers: await _headers()).timeout(_timeout);
|
||||
return _parse(res);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user