Output login errors to user

This commit is contained in:
2025-09-13 20:58:15 +02:00
parent dc0da85688
commit 4aa43d8f20
3 changed files with 84 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart'; // For cache storage
import 'package:sheetless/utility.dart';
import 'sheet.dart';
@@ -15,7 +16,7 @@ class ApiClient {
ApiClient({required this.baseUrl, this.token});
Future<bool> login(String username, String password) async {
Future<Result<void>> login(String username, String password) async {
log.info("Logging in...");
try {
final url = '$baseUrl/login';
@@ -28,14 +29,19 @@ class ApiClient {
if (response.statusCode == 200) {
token = jsonDecode(response.body);
log.info('Login successful');
return true;
return Result.ok(null);
} else {
log.warning('Login failed: ${response.statusCode}, ${response.body}');
return Result.error(
Exception(
"Response code ${response.statusCode}\nResponse: ${response.body}",
),
);
}
} catch (e) {
} on Exception catch (e) {
log.warning('Error during login', e);
return Result.error(e);
}
return false;
}
void logout() {