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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user