mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Check status code before throwing JSON error (#198)
* Check status code before throwing JSON error * Update release notes
This commit is contained in:
parent
2cbcf275ab
commit
e78bb78bfd
@ -1,6 +1,14 @@
|
||||
## InvenTree App Release Notes
|
||||
---
|
||||
|
||||
### 0.8.1 - August 2022
|
||||
---
|
||||
|
||||
- Added extra filtering options for PartCategory list
|
||||
- Added extra filtering options for StockLocation list
|
||||
- Fixed bug related to null widget context
|
||||
- Improved error handling and reporting
|
||||
|
||||
### 0.8.0 - July 2022
|
||||
---
|
||||
|
||||
|
24
lib/api.dart
24
lib/api.dart
@ -810,6 +810,7 @@ class InvenTreeAPI {
|
||||
sentryReportMessage(
|
||||
"Error decoding JSON response from server",
|
||||
context: {
|
||||
"method": "uploadFile",
|
||||
"url": url,
|
||||
"statusCode": response.statusCode.toString(),
|
||||
"data": jsondata,
|
||||
@ -1039,18 +1040,14 @@ class InvenTreeAPI {
|
||||
}
|
||||
} else {
|
||||
|
||||
if (ignoreResponse) {
|
||||
// First check that the returned status code is what we expected
|
||||
if (statusCode != null && statusCode != _response.statusCode) {
|
||||
showStatusCodeError(url, _response.statusCode);
|
||||
} else if (ignoreResponse) {
|
||||
response.data = {};
|
||||
} else {
|
||||
response.data = await responseToJson(url, _response) ?? {};
|
||||
}
|
||||
|
||||
if (statusCode != null) {
|
||||
// Expected status code not returned
|
||||
if (statusCode != _response.statusCode) {
|
||||
showStatusCodeError(url, _response.statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
} on HttpException catch (error) {
|
||||
showServerError(url, L10().serverError, error.toString());
|
||||
@ -1091,14 +1088,25 @@ class InvenTreeAPI {
|
||||
return data ?? {};
|
||||
} on FormatException {
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 400:
|
||||
case 401:
|
||||
case 403:
|
||||
case 404:
|
||||
// Ignore for unauthorized pages
|
||||
break;
|
||||
default:
|
||||
sentryReportMessage(
|
||||
"Error decoding JSON response from server",
|
||||
context: {
|
||||
"headers": response.headers.toString(),
|
||||
"statusCode": response.statusCode.toString(),
|
||||
"data": body.toString(),
|
||||
"endpoint": url,
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
showServerError(
|
||||
url,
|
||||
|
Loading…
x
Reference in New Issue
Block a user