mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 03:26:24 +00:00
Add better error handling for API
This commit is contained in:
parent
0f472d448b
commit
e04dadcd2f
2 changed files with 10 additions and 19 deletions
13
lib/api.dart
13
lib/api.dart
|
|
@ -182,15 +182,22 @@ class InvenTreeAPI {
|
|||
var response = await get("").timeout(Duration(seconds: 10)).catchError((error) {
|
||||
|
||||
if (error is SocketException) {
|
||||
errorMessage = "Could not connect to server.";
|
||||
print(errorMessage);
|
||||
throw errorMessage;
|
||||
print("Could not connect to server");
|
||||
return null;
|
||||
} else if (error is TimeoutException) {
|
||||
print("Server timeout");
|
||||
return null;
|
||||
} else {
|
||||
// Unknown error type, re-throw error
|
||||
print("Unknown error: ${error.toString()}");
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
if (response == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
print("Invalid status code: " + response.statusCode.toString());
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue