2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-12-15 08:38:12 +00:00

API post request now uses HttpClient

This commit is contained in:
Oliver Walters
2021-04-19 21:56:20 +10:00
parent 71340da068
commit b8c535560d
6 changed files with 118 additions and 103 deletions

View File

@@ -262,36 +262,13 @@ class InvenTreeModel {
InvenTreeModel _model;
await api.post(URL, body: data).timeout(Duration(seconds: 10)).catchError((e) {
print("Error during CREATE");
print(e.toString());
if (e is SocketException) {
showServerError(
I18N.of(context).connectionRefused,
e.toString()
);
}
else if (e is TimeoutException) {
showTimeoutError(context);
} else {
// Re-throw the error
throw e;
}
var response = await api.post(URL, body: data);
if (response == null) {
return null;
})
.then((http.Response response) {
// Server should return HTTP_201_CREATED
if (response.statusCode == 201) {
var decoded = json.decode(response.body);
_model = createFromJson(decoded);
} else {
showStatusCodeError(response.statusCode);
}
});
}
return _model;
return createFromJson(response);
}
Future<InvenTreePageResponse> listPaginated(int limit, int offset, {Map<String, String> filters}) async {