This commit is contained in:
2020-05-23 21:53:35 +00:00
parent df630ba9e9
commit 1a0f99d6b9
2 changed files with 18 additions and 12 deletions

View File

@@ -150,16 +150,22 @@ export default {
return Promise.resolve(response);
}
},
json(response) {
extractBody(response) {
if (response.status == 204) {
//no content, nothing to process
return response;
}
let contentType = response.headers.get("content-type");
if (!contentType) {
return response;
}
// console.log("gzapi::JSON method, content type is:", contentType);
if (contentType && contentType.includes("json")) {
if (contentType.includes("json")) {
return response.json();
}
if (contentType.includes("text/plain")) {
return response.text();
}
return response;
},
apiErrorToHumanString(apiError) {
@@ -348,7 +354,7 @@ export default {
return new Promise(function getDataFromServer(resolve, reject) {
fetch(that.APIUrl(route), that.fetchGetOptions())
.then(that.status)
.then(that.json)
.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
resolve(response);
@@ -380,7 +386,7 @@ export default {
}
fetch(that.APIUrl(route), fetchOptions)
.then(that.status)
.then(that.json)
.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
//Note: response.error indicates there is an error, however this is not an unusual condition
@@ -401,7 +407,7 @@ export default {
return new Promise(function removeDataFromServer(resolve, reject) {
fetch(that.APIUrl(route), that.fetchRemoveOptions())
.then(that.status)
//.then(that.json)
//.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
resolve(response);
@@ -420,7 +426,7 @@ export default {
return new Promise(function duplicateRecordOnServer(resolve, reject) {
fetch(that.APIUrl(route), that.fetchPostOptions(null))
.then(that.status)
.then(that.json)
.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
//Note: response.error indicates there is an error, however this is not an unusual condition
@@ -465,7 +471,7 @@ export default {
fetch(that.APIUrl("attachment"), fetchOptions)
.then(that.status)
.then(that.json)
.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
resolve(response);