Skip to content

Commit

Permalink
add some basic error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
seleb committed Dec 21, 2020
1 parent aeb3476 commit b6ed6eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
24 changes: 8 additions & 16 deletions client/client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var base = "https://seans.site/stuff/DYSCOVR";
var client={
// msg: message text
// artiface: ID of artifact to send message for
Expand All @@ -8,20 +9,16 @@ var client={
// datalog:["text","with log","messages"]
// }
postMessage:function(msg,artifact){
$.ajax({
url:"https://seans.site/stuff/DYSCOVR/post_message.php",
return $.ajax({
url: base + "/post_message.php",
async:true,
method:"POST",

data:{
msg:msg,
artifact:artifact
}
}).done(function(data,status,xhr){

}).fail(function(xhr,status,error){
console.error(error);
});
})
},

// artifact: ID of artifact to get messages for
Expand All @@ -35,10 +32,10 @@ postMessage:function(msg,artifact){
// datalog:["text","with log","messages"],
// rows:[{text,rating,timestamp},{text,rating,timestamp},...]
// }
getMessages:function(artifact,sort_column,sort_order,f){
getMessages:function(artifact,sort_column,sort_order){
var artifact=$("input").val();
$.ajax({
url:"https://seans.site/stuff/DYSCOVR/get_messages.php",
return $.ajax({
url: base + "/get_messages.php",
async:true,
method:"POST",

Expand All @@ -47,11 +44,6 @@ getMessages:function(artifact,sort_column,sort_order,f){
sort_column:sort_column,
sort_order:sort_order
}
}).done(function(data,status,xhr){

f(data);
}).fail(function(xhr,status,error){
console.error(error);
});
}
};
};
37 changes: 22 additions & 15 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ $(document).ready(function(){
if(!artifacts[currArt]){
displayMessage("ERROR: You must have an artifact selected to log.")
}else if(p3!="---" && p2!="---" && p1!="---" && artifacts[currArt].done == false){
client.postMessage(p1+' '+p2+' '+p3+".", currArt);
artifacts[currArt].done = true;
displayMessage("Message sent. Thank you for classifying this artifact!");
displayMessage("Sending...");
client.postMessage(p1+' '+p2+' '+p3+".", currArt).done(function(data,status,xhr){
artifacts[currArt].done = true;
displayMessage("Message sent. Thank you for classifying this artifact!");
}).fail(function(xhr,status,error){
displayMessage("ERROR: Message aborted due to server error. Please contact your administrator for more information.");
console.error(error);
});
}else if(artifacts[currArt].done == true){
displayMessage("ERROR: You've already sent a message about this artifact. Please find new artifacts to classify.");
}else{
Expand Down Expand Up @@ -259,20 +264,22 @@ function getMessages(id){
id,
'timestamp',
'ASC',
function(data){
var json = $.parseJSON(data);

if(json.rows.length > 0){
var s="";
for(var i=0;i < json.rows.length; ++i){
s += (json.rows[i].timestamp + ': ' + json.rows[i].text+'\n');
}
displayMessage(s);
}else{
displayMessage("This artifact hasn't been logged before.");
).done(function(data,status,xhr){
var json = $.parseJSON(data);

if(json.rows.length > 0){
var s="";
for(var i=0;i < json.rows.length; ++i){
s += (json.rows[i].timestamp + ': ' + json.rows[i].text+'\n');
}
displayMessage(s);
}else{
displayMessage("This artifact hasn't been logged before.");
}
);
}).fail(function(xhr,status,error){
displayMessage("ERROR: Message aborted due to server error. Please contact your administrator for more information.");
console.error(error);
});
}


Expand Down

0 comments on commit b6ed6eb

Please sign in to comment.