This commit is contained in:
Michael 2019-05-14 12:08:35 +02:00
commit 2feadc12b5
5 changed files with 112 additions and 81 deletions

View File

@ -199,21 +199,16 @@
this.$store.commit('cacheCollector/RESET_NEW_CACHE'); this.$store.commit('cacheCollector/RESET_NEW_CACHE');
this.$router.push({path: '/overview'}); this.$router.push({path: '/overview'});
}).catch((error) => { }).catch((error) => {
//TODO: Fehlermeldungen
// Error
let msg; let msg;
let title; let title;
if (error.response) { if (error.response) {
// The request was made and the server responded with a status code title = "Bitte Eingaben überprüfen!";
title = "Problem with response!"; msg = error.response.data;
msg = error.response;
} else if (error.request) { } else if (error.request) {
// The request was made but no response was received title = "Verbindungsfehler!";
title = "Problem with request!"; msg = "Es konnte keine Verbindung zum Server aufgebaut werden. Versuchen Sie es später noch einmal!"
msg = "Error occured due to wrong server request!"
console.log(error.request); console.log(error.request);
} else { } else {
// Something happened in setting up the request that triggered an Error
title = "Error"; title = "Error";
msg = error.message; msg = error.message;
console.log('Error', error.message); console.log('Error', error.message);
@ -227,7 +222,24 @@
console.log("POST api/editCache: " + response.statusText); console.log("POST api/editCache: " + response.statusText);
this.$store.commit('cacheCollector/RESET_NEW_CACHE'); this.$store.commit('cacheCollector/RESET_NEW_CACHE');
this.$router.push({path: '/overview'}); this.$router.push({path: '/overview'});
}) }).catch((error) => {
let msg;
let title;
if (error.response) {
title = "Bitte Eingaben überprüfen!";
msg = error.response.data;
} else if (error.request) {
title = "Verbindungsfehler!";
msg = "Es konnte keine Verbindung zum Server aufgebaut werden. Versuchen Sie es später noch einmal!"
console.log(error.request);
} else {
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
} }
}, },
}, },

View File

@ -109,29 +109,24 @@
localStorage.setItem('userMail', JSON.stringify(data.email)); localStorage.setItem('userMail', JSON.stringify(data.email));
this.evalAuthentication(); this.evalAuthentication();
this.$router.push({path: `/overview`}) this.$router.push({path: `/overview`})
}) }).catch((error) => {
.catch((error) => { let msg;
let message; let title;
let header = "Fehler: "; if (error.response) {
if (error.response) { title = "Fehler!";
console.log("ERROR RESPONSE"); msg = error.response.data;
// The request was made and the server responded with a status code } else if (error.request) {
// that falls out of the range of 2xx title = "Verbindungsfehler!";
message = error.response.data.error; msg = "Es konnte keine Verbindung zum Server aufgebaut werden. Versuchen Sie es später noch einmal!"
header += error.response.status; console.log(error.request);
} else if (error.request) { } else {
// The request was made but no response was received title = "Error";
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of msg = error.message;
// http.ClientRequest in node.js console.log('Error', error.message);
message = "Anfrage fehlgeschlagen."; }
} else { console.log(error.config);
// Something happened in setting up the request that triggered an Error this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
console.log('Error', error.message); }).finally(() => {
message = error.message;
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, });
}).finally(() => {
this.loading = false; this.loading = false;
this.evalAuthentication(); this.evalAuthentication();
}) })

View File

@ -165,26 +165,22 @@
this.initMap(); this.initMap();
resolve(true); resolve(true);
}).catch((error) => { }).catch((error) => {
let message; let msg;
let header = "Fehler: "; let title;
if (error.response) { if (error.response) {
console.log("ERROR RESPONSE"); title = "Bitte Eingaben überprüfen!";
// The request was made and the server responded with a status code msg = error.response.data;
// that falls out of the range of 2xx
message = error.response.data.error;
header += error.response.status;
} else if (error.request) { } else if (error.request) {
// The request was made but no response was received title = "Verbindungsfehler!";
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of msg = "Es konnte keine Verbindung zum Server aufgebaut werden. Versuchen Sie es später noch einmal!"
// http.ClientRequest in node.js console.log(error.request);
message = "Anfrage fehlgeschlagen.";
} else { } else {
// Something happened in setting up the request that triggered an Error title = "Error";
msg = error.message;
console.log('Error', error.message); console.log('Error', error.message);
message = error.message;
} }
console.log(error.config); console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: message, title: header,}); this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
resolve(true); resolve(true);
}) })
}) })
@ -258,26 +254,22 @@
.then((response) => { .then((response) => {
this.loadData(); this.loadData();
}).catch((error) => { }).catch((error) => {
let message; let msg;
let header = "Fehler: "; let title;
if (error.response) { if (error.response) {
console.log("ERROR RESPONSE"); title = "Fehler!";
// The request was made and the server responded with a status code msg = error.response.data;
// that falls out of the range of 2xx
message = error.response.data.error;
header += error.response.status;
} else if (error.request) { } else if (error.request) {
// The request was made but no response was received title = "Verbindungsfehler!";
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of msg = "Es konnte keine Verbindung zum Server aufgebaut werden. Versuchen Sie es später noch einmal!"
// http.ClientRequest in node.js console.log(error.request);
message = "Anfrage fehlgeschlagen.";
} else { } else {
// Something happened in setting up the request that triggered an Error title = "Error";
msg = error.message;
console.log('Error', error.message); console.log('Error', error.message);
message = error.message;
} }
console.log(error.config); console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: message, title: header,}); this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
}) })
}, },
startCache(cacheID) { startCache(cacheID) {
@ -299,9 +291,24 @@
console.log(response.data); console.log(response.data);
currentStationID = response.data.aktuelleStation.id; currentStationID = response.data.aktuelleStation.id;
this.$router.push({path: `/station/${cacheID}/${currentStationID}`}); this.$router.push({path: `/station/${cacheID}/${currentStationID}`});
}) }).catch((error) => {
.catch((error) => { let msg;
}); let title;
if (error.response) {
title = "Fehler!";
msg = error.response.data;
} else if (error.request) {
title = "Verbindungsfehler!";
msg = "Es konnte keine Verbindung zum Server aufgebaut werden. Versuchen Sie es später noch einmal!"
console.log(error.request);
} else {
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
} }
}, },
goToReward(cacheID) { goToReward(cacheID) {
@ -316,9 +323,24 @@
console.log(response.data); console.log(response.data);
currentStationID = response.data.aktuelleStation.id; currentStationID = response.data.aktuelleStation.id;
this.$router.push({path: `/CacheEnd/${params.cacheID}`}); this.$router.push({path: `/CacheEnd/${params.cacheID}`});
}) }).catch((error) => {
.catch((error) => { let msg;
}); let title;
if (error.response) {
title = "Fehler!";
msg = error.response.data;
} else if (error.request) {
title = "Verbindungsfehler!";
msg = "Es konnte keine Verbindung zum Server aufgebaut werden. Versuchen Sie es später noch einmal!"
console.log(error.request);
} else {
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
} }
}, },

View File

@ -1,6 +1,7 @@
package hhn.labsw.bugageocaching.controller; package hhn.labsw.bugageocaching.controller;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import hhn.labsw.bugageocaching.entities.*; import hhn.labsw.bugageocaching.entities.*;
import hhn.labsw.bugageocaching.helper.POI; import hhn.labsw.bugageocaching.helper.POI;
import hhn.labsw.bugageocaching.helper.RankingListHelper; import hhn.labsw.bugageocaching.helper.RankingListHelper;
@ -475,6 +476,7 @@ public class Controller {
sendBackUsers.add(tmp); sendBackUsers.add(tmp);
} }
logger.debug("/api/getRankingList Converted Objects to RankingListHelper"); logger.debug("/api/getRankingList Converted Objects to RankingListHelper");
logger.debug("/api/getRankingList RankingList: " + new GsonBuilder().setPrettyPrinting().create().toJson(sendBackUsers));
return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers)); return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers));
} }

View File

@ -56,24 +56,24 @@ public class CacheConstructionUtil {
// Caches werden in die Datenbank eingetragen // Caches werden in die Datenbank eingetragen
if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) { if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) {
deleteStationenUtil(cache); deleteStationenUtil(cache);
return ResponseEntity.status(400).body("cache fields can´t be empty"); return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
} }
if (cache.getStationen().size() < 2) { if (cache.getStationen().size() < 2) {
deleteStationenUtil(cache); deleteStationenUtil(cache);
return ResponseEntity.status(400).body("a cache needs atleast 2 stations"); return ResponseEntity.status(400).body("Ein Cache muss mindestens zwei Stationen besitzen.\nBitte füge noch eine Station hinzu!");
} }
for (Cache cache1 : cacheRepository.findAll()) { for (Cache cache1 : cacheRepository.findAll()) {
if (cache1.getName().equals(cache.getName())) { if (cache1.getName().equals(cache.getName())) {
deleteStationenUtil(cache); deleteStationenUtil(cache);
return ResponseEntity.status(400).body("name is already taken"); return ResponseEntity.status(400).body("Der Cachename ist bereits vergeben. Bitte wähle einen anderen Name!");
} }
} }
if (cache.getRankingPoints() < 0) { if (cache.getRankingPoints() < 0) {
deleteStationenUtil(cache); deleteStationenUtil(cache);
return ResponseEntity.status(400).body("Ranking points has to be a positive number"); return ResponseEntity.status(400).body("Die Punkte für den Cache dürfen nicht negativ sein!");
} }
cacheRepository.save(cache); cacheRepository.save(cache);
@ -84,15 +84,15 @@ public class CacheConstructionUtil {
public static ResponseEntity createStationUtil(Station station) { public static ResponseEntity createStationUtil(Station station) {
if (station.getDescription().length() == 0 || station.getLattitude() == 0.0 || station.getLongitude() == 0.0 /*|| station.getSolution().length() == 0*/) { if (station.getDescription().length() == 0 || station.getLattitude() == 0.0 || station.getLongitude() == 0.0 /*|| station.getSolution().length() == 0*/) {
return ResponseEntity.status(400).body("station fields can´t be empty"); return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
} }
if (station.getLattitude() < 9 || station.getLattitude() > 10) { if (station.getLattitude() < 9 || station.getLattitude() > 10) {
return ResponseEntity.status(400).body("Lattitude has to be between 9 and 10 degrees"); return ResponseEntity.status(400).body("Die Lattitude ist außerhalb der Bundesgartenschau");
} }
if (station.getLongitude() < 49 || station.getLongitude() > 50) { if (station.getLongitude() < 49 || station.getLongitude() > 50) {
return ResponseEntity.status(400).body("Longitude has to be in the range of 49 to 50 degrees"); return ResponseEntity.status(400).body("Die Longitude ist außerhalb der Bundesgartenschau");
} }
Random r = new Random(); Random r = new Random();
@ -114,7 +114,7 @@ public class CacheConstructionUtil {
try { try {
station.setCode(code); station.setCode(code);
} catch (RollbackException e) { } catch (RollbackException e) {
return ResponseEntity.status(400).body("There was an error generating the unique code"); return ResponseEntity.status(400).body("Es gab einen Fehler beim Konsturieren der QR Codes");
} }
stationRepository.save(station); stationRepository.save(station);
@ -130,7 +130,7 @@ public class CacheConstructionUtil {
oldCache = oldCacheOptional.get(); oldCache = oldCacheOptional.get();
// oldStationen = new ArrayList<>(oldCache.getStationen()); // oldStationen = new ArrayList<>(oldCache.getStationen());
} else { } else {
return ResponseEntity.status(404).body("There isnt a cache with the id " + cache.getId()); return ResponseEntity.status(404).body("Es gab einen Fehler. Bitte versuchen Sie es erneut oder kontaktieren Sie einen Admin.");
} }
ResponseEntity response = new ResponseEntity(HttpStatus.ACCEPTED); ResponseEntity response = new ResponseEntity(HttpStatus.ACCEPTED);
@ -168,26 +168,26 @@ public class CacheConstructionUtil {
// überprüft den Cache nach validen Daten // überprüft den Cache nach validen Daten
if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) { if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) {
deleteNewCreatedStationsUtil(newCreatedStationList); deleteNewCreatedStationsUtil(newCreatedStationList);
return ResponseEntity.status(400).body("cache fields can´t be empty"); return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt sein!");
} }
if (cache.getStationen().size() < 2) { if (cache.getStationen().size() < 2) {
deleteNewCreatedStationsUtil(newCreatedStationList); deleteNewCreatedStationsUtil(newCreatedStationList);
return ResponseEntity.status(400).body("a cache needs atleast 2 stations"); return ResponseEntity.status(400).body("Ein Cache muss mindestens zwei Stationen haben. Bitte füge eine weiter Station hinzu!");
} }
for (Cache cache1 : cacheRepository.findAll()) { for (Cache cache1 : cacheRepository.findAll()) {
if (cache1.getName().equals(cache.getName())) { if (cache1.getName().equals(cache.getName())) {
if (cache1.getId() != oldCache.getId()) { if (cache1.getId() != oldCache.getId()) {
deleteNewCreatedStationsUtil(newCreatedStationList); deleteNewCreatedStationsUtil(newCreatedStationList);
return ResponseEntity.status(400).body("name is already taken"); return ResponseEntity.status(400).body("Der Cachename ist bereits vergeben. Bitte wähle einen anderen!");
} }
} }
} }
if (cache.getRankingPoints() < 0) { if (cache.getRankingPoints() < 0) {
deleteNewCreatedStationsUtil(newCreatedStationList); deleteNewCreatedStationsUtil(newCreatedStationList);
return ResponseEntity.status(400).body("Ranking points has to be a positive number"); return ResponseEntity.status(400).body("Die Punkte für den Cache dürfen nicht negativ sein!");
} }
cacheRepository.save(cache); cacheRepository.save(cache);
@ -242,7 +242,7 @@ public class CacheConstructionUtil {
public static ResponseEntity deleteCacheUtil(String cacheID) { public static ResponseEntity deleteCacheUtil(String cacheID) {
Optional<Cache> optionalCache = cacheRepository.findById(Integer.valueOf(cacheID)); Optional<Cache> optionalCache = cacheRepository.findById(Integer.valueOf(cacheID));
if (!optionalCache.isPresent()) { if (!optionalCache.isPresent()) {
return ResponseEntity.status(404).body(new Gson().toJson("There is no cache with the ID " + cacheID)); return ResponseEntity.status(404).body(new Gson().toJson("Es gab einen Fehler beim Löschen des Caches"));
} }
Cache cache = optionalCache.get(); Cache cache = optionalCache.get();