Skip to content
Snippets Groups Projects
Commit d6fe6940 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Add file to event in case of error (VPU/Middleware/API#40)

parent e6d3156d
No related branches found
No related tags found
No related merge requests found
......@@ -103,20 +103,28 @@ class VPUFileUpload extends VPULitElement {
this.asyncForEach(files, async (file) => this.uploadFile(file));
}
sendFinishedEvent(response, file) {
sendFinishedEvent(response, file, sendFile = false) {
response.json().then((json) => {
const data = {
let data = {
status: response.status,
filename: file.name,
json: json
};
if (sendFile) {
data.file = file;
}
console.log(data);
const event = new CustomEvent("vpu-fileupload-finished", { "detail": data, bubbles: true, composed: true });
this.dispatchEvent(event);
});
}
/**
* @param file
* @returns {Promise<void>}
*/
async uploadFile(file) {
let url = this.url;
let formData = new FormData();
......@@ -133,12 +141,12 @@ class VPUFileUpload extends VPULitElement {
.then((response) => {
/* Done. Inform the user */
console.log(`Status: ${response.status} for file ${file.name}`);
this.sendFinishedEvent(response, file);
this.sendFinishedEvent(response, file, response.status === 503);
})
.catch((response) => {
/* Error. Inform the user */
console.log(`Error status: ${response.status} for file ${file.name}`);
this.sendFinishedEvent(response, file);
this.sendFinishedEvent(response, file, true);
})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment