Skip to content

Commit

Permalink
Fix invalid API response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrumpis committed Mar 9, 2024
1 parent 328d48b commit e1d9e6f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ function importFiles(apiPath, formData) {
const data = JSON.parse(xhr.responseText);
if (data.error) {
error(`Import Error: ${data.error}`);
} else {
success("Success!");
} else if (data.length) {
if (data.import && data.import.length) {
success("Success!");
success(`Imported IDs: ${data.import.join(', ')}`);
}
if (data.update && data.update.length) {
success("Success!");
success(`Updated IDs: ${data.update.join(', ')}`);
}
} else {
error(`API Error: no response`);
}
} catch (e) {
console.error(e);
Expand Down

0 comments on commit e1d9e6f

Please sign in to comment.