This commit is contained in:
@@ -22,7 +22,7 @@ export default {
|
||||
//debugger;
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return Promise.resolve(response);
|
||||
} else {
|
||||
} else {
|
||||
store.commit(
|
||||
"logItem",
|
||||
"API error: status=" +
|
||||
@@ -32,25 +32,9 @@ export default {
|
||||
", url=" +
|
||||
response.url
|
||||
);
|
||||
return Promise.reject(new Error(response.statusText));
|
||||
}
|
||||
},
|
||||
status2(response) {
|
||||
//debugger;
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return Promise.resolve(response);
|
||||
} else {
|
||||
store.commit(
|
||||
"logItem",
|
||||
"API error: status=" +
|
||||
response.status +
|
||||
", statusText=" +
|
||||
response.statusText +
|
||||
", url=" +
|
||||
response.url
|
||||
);
|
||||
|
||||
|
||||
//TODO: If no viable data to return then should reject, otherwise should resolve regardless
|
||||
//Nope because we will never get here if nothing at all was returned so what is this actually doing??
|
||||
|
||||
return Promise.resolve(response);
|
||||
}
|
||||
@@ -58,6 +42,14 @@ export default {
|
||||
json(response) {
|
||||
return response.json();
|
||||
},
|
||||
apiErrorToHumanString(apiError) {
|
||||
//empty error object?
|
||||
if (!apiError) {
|
||||
return "apiErrorToHumanString():: Empty API eror, unknown";
|
||||
}
|
||||
//convert to readable string
|
||||
return JSON.stringify(apiError);
|
||||
},
|
||||
patchAuthorizedHeaders() {
|
||||
return {
|
||||
//Accept: "application/json, text/plain, */*",
|
||||
@@ -166,5 +158,30 @@ export default {
|
||||
eq +
|
||||
encodeURIComponent(stringifyPrimitive(obj))
|
||||
);
|
||||
},
|
||||
get(route) {
|
||||
var that=this;
|
||||
//debugger;
|
||||
return new Promise(function(resolve, reject) {
|
||||
//debugger;
|
||||
fetch(that.APIUrl(route), that.fetchGetOptions())
|
||||
.then(that.status)
|
||||
.then(that.json)
|
||||
.then(response => {
|
||||
//For now, assuming that all returns that make it here have either an error or a data object attached to them
|
||||
//debugger;
|
||||
resolve(response);
|
||||
})
|
||||
.catch(function(error) {
|
||||
//fundamental error, can't proceed with this call
|
||||
// debugger;
|
||||
var errorMessage =
|
||||
"API error: GET route =" + route + ", message =" + error.message;
|
||||
store.commit("logItem", errorMessage);
|
||||
alert("Error: " + errorMessage);
|
||||
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
/* eslint-disable */
|
||||
/* xeslint-disable */
|
||||
import apiUtil from "./apiutil";
|
||||
import store from "../store";
|
||||
export default {
|
||||
get(route) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
fetch(apiUtil.APIUrl(route), apiUtil.fetchGetOptions())
|
||||
.then(apiUtil.status2)
|
||||
.then(apiUtil.status)
|
||||
.then(apiUtil.json)
|
||||
.then(response => {
|
||||
//For now, assuming that all returns that make it here have either an error or a data object attached to them
|
||||
//debugger;
|
||||
resolve(response);
|
||||
})
|
||||
.catch(function(error) {
|
||||
//fundamental error, can't proceed with this call
|
||||
// debugger;
|
||||
// debugger;
|
||||
var errorMessage =
|
||||
"API error: GET route =" + route + ", message =" + error.message;
|
||||
store.commit("logItem", errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user