Skip to content

Commit f0bf653

Browse files
authored
Merge pull request doccano#157 from CatalystCode/bugfix/show-error-on-data-import
Bugfix/Correctly display dataset upload errors
2 parents 5862b37 + e56699f commit f0bf653

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

app/server/static/js/upload.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,24 @@ const vm = new Vue({ // eslint-disable-line no-unused-vars
3333
})
3434
.catch((error) => {
3535
this.isLoading = false;
36-
if ('detail' in error.response.data) {
37-
this.messages.push(error.response.data.detail);
38-
} else if ('text' in error.response.data) {
39-
this.messages = error.response.data.text;
40-
}
36+
this.handleError(error);
4137
});
4238
},
4339

40+
handleError(error) {
41+
const problems = Array.isArray(error.response.data)
42+
? error.response.data
43+
: [error.response.data];
44+
45+
problems.forEach((problem) => {
46+
if ('detail' in problem) {
47+
this.messages.push(problem.detail);
48+
} else if ('text' in problem) {
49+
this.messages = problem.text;
50+
}
51+
});
52+
},
53+
4454
download() {
4555
const headers = {};
4656
if (this.format === 'csv') {
@@ -66,11 +76,7 @@ const vm = new Vue({ // eslint-disable-line no-unused-vars
6676
document.body.appendChild(link);
6777
link.click();
6878
}).catch((error) => {
69-
if ('detail' in error.response.data) {
70-
this.messages.push(error.response.data.detail);
71-
} else if ('text' in error.response.data) {
72-
this.messages = error.response.data.text;
73-
}
79+
this.handleError(error);
7480
});
7581
},
7682
},

0 commit comments

Comments
 (0)