mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Catch JSON decode errors when trying to extract user roles from an older server
This commit is contained in:
parent
096c4e86dc
commit
b8497d3c20
12
lib/api.dart
12
lib/api.dart
@ -359,6 +359,8 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
roles.clear();
|
roles.clear();
|
||||||
|
|
||||||
|
print("Requesting user role data");
|
||||||
|
|
||||||
// Next we request the permissions assigned to the current user
|
// Next we request the permissions assigned to the current user
|
||||||
// Note: 2021-02-27 this "roles" feature for the API was just introduced.
|
// Note: 2021-02-27 this "roles" feature for the API was just introduced.
|
||||||
// Any 'older' version of the server allows any API method for any logged in user!
|
// Any 'older' version of the server allows any API method for any logged in user!
|
||||||
@ -369,16 +371,24 @@ class InvenTreeAPI {
|
|||||||
print(error);
|
print(error);
|
||||||
}).then((response) {
|
}).then((response) {
|
||||||
|
|
||||||
|
print("Response status: ${response.statusCode}");
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
|
|
||||||
// Convert response to JSON representation
|
// Convert response to JSON representation
|
||||||
|
|
||||||
|
try {
|
||||||
var data = json.decode(response.body);
|
var data = json.decode(response.body);
|
||||||
if (data.containsKey('roles')) {
|
if (data.containsKey('roles')) {
|
||||||
|
|
||||||
// Save a local copy of the user roles
|
// Save a local copy of the user roles
|
||||||
roles = data['roles'];
|
roles = data['roles'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
on FormatException {
|
||||||
|
// Old server has re-directed away from the API
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user