This commit is contained in:
2019-02-28 18:34:09 +00:00
parent d4b555b75f
commit ab083d3890

View File

@@ -21,8 +21,6 @@ var stringifyPrimitive = function(v) {
export default { export default {
status(response) { status(response) {
//debugger;
if (response.status == 401) { if (response.status == 401) {
//must reject if not authorized //must reject if not authorized
return Promise.reject(new Error("401 - NOT AUTHORIZED")); return Promise.reject(new Error("401 - NOT AUTHORIZED"));
@@ -48,7 +46,6 @@ export default {
} }
}, },
json(response) { json(response) {
//debugger;
return response.json(); return response.json();
}, },
apiErrorToHumanString(apiError) { apiErrorToHumanString(apiError) {
@@ -171,26 +168,26 @@ export default {
}, },
get(route) { get(route) {
var that = this; var that = this;
//debugger;
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
//debugger;
fetch(that.APIUrl(route), that.fetchGetOptions()) fetch(that.APIUrl(route), that.fetchGetOptions())
.then(that.status) .then(that.status)
.then(that.json) .then(that.json)
.then(response => { .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); resolve(response);
}) })
.catch(function(error) { .catch(function(error) {
//fundamental error, can't proceed with this call //fundamental error, can't proceed with this call
// debugger;
var errorMessage = var errorMessage =
"API error: GET route =" + route + ", message =" + error.message; "API error: GET route =" + route + ", message =" + error.message;
store.commit("logItem", errorMessage); store.commit("logItem", errorMessage);
alert("Error: " + errorMessage); alert("Error: " + errorMessage);
reject(error); reject(error);
if (error.message && error.message.includes("401")) { if (error.message && error.message.includes("401")) {
store.commit(
"logItem",
"User is not authorized, redirecting to login"
);
auth.logout(); auth.logout();
router.push("/login"); router.push("/login");
} }