1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

distinguish between file and Json in processing response of GET operation

This commit is contained in:
Sonja Happ 2020-03-18 16:27:58 +01:00
parent 0de876f608
commit 6f34cacab9
2 changed files with 17 additions and 2 deletions

View file

@ -66,7 +66,16 @@ class RestAPI {
if (res == null || res.status !== 200) {
reject(error);
} else {
resolve(JSON.parse(res.text));
if (res.type ==="application/json"){
resolve(JSON.parse(res.text));
} else {
// if received data is not JSON it is a File
//create file name:
let parts = url.split("/");
console.log("res.text has type: ", typeof res.text);
resolve({data: res.text, type: res.type, id: parts[parts.length-1]})
}
}
});
});

View file

@ -88,7 +88,13 @@ class RestDataManager {
if (id != null) {
// load single object
RestAPI.get(this.requestURL('load/add',id,param), token).then(response => {
const data = this.filterKeys(response[this.type]);
let data;
if (response.hasOwnProperty(this.type)) {
data = this.filterKeys(response[this.type]);
}else{
// loaded file
data = response;
}
AppDispatcher.dispatch({
type: this.type + 's/loaded',