Skip to content

Commit

Permalink
Add error function and check for front-end
Browse files Browse the repository at this point in the history
Relates #64
  • Loading branch information
MynahMarie committed Nov 30, 2017
1 parent 7a2e0bd commit 8f038a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions public/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function onError(status) {
if (status === 404) {
alert("File Not Found");
} else {
alert("We are sorry, there was an error on our side");
}
}

function keepRunning() {
watch.seconds = watch.seconds + 1;
if (watch.seconds == 60) {
Expand All @@ -19,6 +27,9 @@ function fetch(url, callback) {
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
callback(null, JSON.parse(xhr.responseText));
} else if (xhr.status !== 200){
callback(xhr.status);
console.log(xhr.readyState, xhr.status);
} else {
console.log(xhr.readyState, xhr.status);
}
Expand All @@ -34,8 +45,9 @@ function filterData() {

fetch(searchPath, function(error, response) {
if (error) {
onError(response);
console.log('error with getting data from the server : ', error);
} else {
} else if (response) {
var clock = JSON.parse(response.clock);
var timeL = clock.formatted.split(' ')[1].split(':');
watch.hours = parseInt(timeL[0]);
Expand All @@ -50,7 +62,6 @@ function filterData() {
function renderInfos(response) {
var time_infos = JSON.parse(response.clock);
var weather_infos = JSON.parse(response.weather);

document.getElementById('weather').style.backgroundColor = '#66d3ff';
document.getElementById('other').style.backgroundColor = '#d2d7dd';

Expand Down
Empty file removed tests/front-endTesting.js
Empty file.

0 comments on commit 8f038a8

Please sign in to comment.