Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions IntelliQ/backend/src/main/webapp/static/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,38 +241,42 @@ var intelliqApi = function(){
api.lastRequestTimestamp = (new Date()).getTime();
//xhr.setRequestHeader("X-Mashape-Authorization", api.apiKey);
},
success : function(data) {
success : function(data, status, xhr) {
request.data = data;
// check if the API returned a valid response
if (data.statusCode != null && data.statusCode == 200) {
if (data.statusCode && data.statusCode == 200) {
// looks good
if (request.onSuccessCallback != null) {
request.onSuccessCallback(data);
}
resolve(data);
} else {
// something went wrong, try to extract error message
if (data.statusMessage != null) {
this.error(data.statusMessage);
if (data.statusMessage) {
this.error(xhr, status, data.statusMessage);
} else {
this.error("Request didn't return a valid response: " + data);
this.error(xhr, status, "Request didn't return a valid response:\n" + JSON.stringify(data));
}
}
},
error : function(error) {
error : function(xhr, status, error) {
console.log(xhr);
console.log(status);
console.log(error);

request.error = error;
log(error)

if (typeof error == 'string') {
log(error);
request.data = "{ \"error\": \"" + error + "\" }";
if (xhr.responseText) {
request.data = JSON.parse(xhr.responseText);
} else {
log(error.responseText);
request.data = error.responseJSON;
request.data = { "error": error };
}

if (request.onErrorCallback != null) {
request.onErrorCallback(error);
}

reject(error);
},
complete : function (){
Expand Down
26 changes: 16 additions & 10 deletions IntelliQ/backend/src/main/webapp/static/js/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ var authenticator = function(){
}

var onGoogleSignInInitializationFailed = function(error) {
log("Google authentication initialization failed: " + error);
log("Google authentication initialization failed: " + JSON.stringify(error));
authenticator.googleAuthenticationInitializing = false;
authenticator.googleAuthenticationInitialized = false;
if (error.error) {
if (error.error === "popup_closed_by_user") {
reject("Sign in canceled by user");
return;
}
}
reject(error);
}

googleAuth.then(onGoogleSignInInitialized, onGoogleSignInInitializationFailed);
}

if (gapi.auth2 == null) {
if (!gapi.auth2) {
log("Requesting Google auth2 API");
authenticator.googleAuthenticationInitializing = true;
gapi.load('auth2', onAuthApiAvailable);
Expand All @@ -106,8 +112,8 @@ var authenticator = function(){
log("Google sign in failed: " + error);
reject(error);
});
} catch (ex) {
log("Google sign in invoking failed: " + ex);
} catch (error) {
log("Google sign in invoking failed: " + error);
reject(error);
}
}).catch(function(error) {
Expand All @@ -130,8 +136,8 @@ var authenticator = function(){
log("Google sign out failed: " + error);
reject(error);
});
} catch (ex) {
log("Google sign out invoking failed: " + ex);
} catch (error) {
log("Google sign out invoking failed: " + error);
reject(error);
}
}).catch(function(error) {
Expand All @@ -154,8 +160,8 @@ var authenticator = function(){
log("Google disconnection failed: " + error);
reject(error);
});
} catch (ex) {
log("Google disconnection invoking failed: " + ex);
} catch (error) {
log("Google disconnection invoking failed: " + error);
reject(error);
}
}).catch(function(error) {
Expand All @@ -182,7 +188,7 @@ var authenticator = function(){
authenticator.getGoogleSignInStatus = function() {
try {
return gapi.auth2.getAuthInstance().isSignedIn.get();
} catch (ex) {
} catch (error) {
log("Unable to get Google sign in status")
return false;
}
Expand All @@ -203,7 +209,7 @@ var authenticator = function(){
authenticator.getGoogleUser = function() {
try {
return gapi.auth2.getAuthInstance().currentUser.get();
} catch (ex) {
} catch (error) {
log("Unable to get Google user")
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions IntelliQ/backend/src/main/webapp/static/js/manage_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function requestQueue() {
reject("Queue not found");
}
}).catch(function(error){
reject("Unable to get queue: " + error);
reject("Unable to get queue: " + JSON.stringify(error));
console.log(error);
});
});
Expand All @@ -78,7 +78,7 @@ function requestQueueItems() {
queueItems = intelliqApi.sortQueueItems(queueItems).byTicketNumber();
resolve(queueItems);
}).catch(function(error){
reject("Unable to get queue items: " + error);
reject("Unable to get queue items: " + JSON.stringify(error));
console.log(error);
});
});
Expand Down
5 changes: 4 additions & 1 deletion IntelliQ/backend/src/main/webapp/static/js/webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ function requestNearbyQueues() {
});
}).catch(function(error){
console.log(error);
ui.showErrorMessage(getString("locationUnavailable") + ": " + JSON.stringify(error));
if (typeof error !== "string") {
error = "\n" + JSON.stringify(error)
}
ui.showErrorMessage(getString("locationUnavailable") + ": " + error);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="${staticUrl}js/materialize.js"></script>
<script src="${staticUrl}js/init.js"></script>
<script src="${staticUrl}js/analyze.js"></script>
<script src="${staticUrl}js/tracking.js"></script>
<script src="${staticUrl}js/general.js"></script>
<script src="${staticUrl}js/authenticator.js" defer></script>
<script src="${staticUrl}js/api.js" defer></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="${staticUrl}js/materialize.js"></script>
<script src="${staticUrl}js/init.js"></script>
<script src="${staticUrl}js/analyze.js"></script>
<script src="${staticUrl}js/tracking.js"></script>
<script src="${staticUrl}js/general.js"></script>
<script src="${staticUrl}js/authenticator.js" defer></script>
<script src="${staticUrl}js/api.js" defer></script>
Expand Down