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
|
## 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
|
### 0.8.0 - July 2022
|
||||||
---
|
---
|
||||||
|
|
||||||
|
40
lib/api.dart
40
lib/api.dart
@ -810,6 +810,7 @@ class InvenTreeAPI {
|
|||||||
sentryReportMessage(
|
sentryReportMessage(
|
||||||
"Error decoding JSON response from server",
|
"Error decoding JSON response from server",
|
||||||
context: {
|
context: {
|
||||||
|
"method": "uploadFile",
|
||||||
"url": url,
|
"url": url,
|
||||||
"statusCode": response.statusCode.toString(),
|
"statusCode": response.statusCode.toString(),
|
||||||
"data": jsondata,
|
"data": jsondata,
|
||||||
@ -1039,18 +1040,14 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
} else {
|
} 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 = {};
|
response.data = {};
|
||||||
} else {
|
} else {
|
||||||
response.data = await responseToJson(url, _response) ?? {};
|
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) {
|
} on HttpException catch (error) {
|
||||||
showServerError(url, L10().serverError, error.toString());
|
showServerError(url, L10().serverError, error.toString());
|
||||||
@ -1091,14 +1088,25 @@ class InvenTreeAPI {
|
|||||||
return data ?? {};
|
return data ?? {};
|
||||||
} on FormatException {
|
} on FormatException {
|
||||||
|
|
||||||
sentryReportMessage(
|
switch (response.statusCode) {
|
||||||
"Error decoding JSON response from server",
|
case 400:
|
||||||
context: {
|
case 401:
|
||||||
"headers": response.headers.toString(),
|
case 403:
|
||||||
"statusCode": response.statusCode.toString(),
|
case 404:
|
||||||
"data": body.toString(),
|
// 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(
|
showServerError(
|
||||||
url,
|
url,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user