This commit is contained in:
2019-01-04 21:19:52 +00:00
parent 8fe9cca33a
commit 713a788ffd
3 changed files with 64 additions and 48 deletions

View File

@@ -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);
});
});
}
};

View File

@@ -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);

View File

@@ -1,8 +1,8 @@
/* eslint-disable */
/* xeslint-disable */
import store from "../store";
import roles from "./roles";
import lt from "../api/locale";
import api from "../api/getAPIItem";
import api from "../api/apiutil";
function addNavItem(title, icon, route) {
store.commit("addNavItem", {
@@ -17,8 +17,7 @@ function addNavItem(title, icon, route) {
// on change of authentication status
export default function initialize() {
if (store.state.authenticated) {
//GET LOCALIZED TEXT FOR SHELL
//GET LOCALIZED TEXT FOR SHELL
lt.fetch([
"Home",
"Service",
@@ -89,32 +88,32 @@ export default function initialize() {
throw error;
});
//CACHE LOCALE SETTINGS
debugger;
//CACHE LOCALE SETTINGS
//check the timezone offset is still valid, offer to change it if not
//api.get("UserOptions/" + store.state.userId).then(res => {
api
.get("UserOptions/bb")
.then(res => {
debugger;
if (res.error) {
//In a form this would trigger a bunch of validation or error display code but for here and now:
//convert error to human readable string for display
alert(api.apiErrorToHumanString(res.error));
} else {
var localOffset = new Date().getTimezoneOffset();
if (localOffset != 0) {
localOffset = (localOffset / 60) * -1; //time is in minutes and reversed from what we want or expect
}
//TODO: check if error in return object
//centralize that shit so can easily handle it in client
var localOffset = new Date().getTimezoneOffset();
if (localOffset != 0) {
localOffset = (localOffset / 60) * -1; //time is in minutes and reversed from what we want or expect
}
if (res.data.timeZoneOffset != localOffset) {
//todo: timezone doesn't match, offer to fix it
alert(
"Time zone offset for this account is set to " +
res.data.timeZoneOffset +
" which doesn't match the local timezone offset of " +
localOffset +
"."
);
if (res.data.timeZoneOffset != localOffset) {
//todo: timezone doesn't match, offer to fix it
alert(
"Time zone offset for this account is set to " +
res.data.timeZoneOffset +
" which doesn't match the local timezone offset of " +
localOffset +
"."
);
}
}
})
.catch(function(error) {
@@ -124,7 +123,5 @@ export default function initialize() {
);
throw error;
});
}
}