mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 03:26:24 +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
2 changed files with 32 additions and 16 deletions
40
lib/api.dart
40
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 {
|
||||
|
||||
sentryReportMessage(
|
||||
"Error decoding JSON response from server",
|
||||
context: {
|
||||
"headers": response.headers.toString(),
|
||||
"statusCode": response.statusCode.toString(),
|
||||
"data": body.toString(),
|
||||
}
|
||||
);
|
||||
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…
Add table
Add a link
Reference in a new issue