Skip to content

Commit 150aede

Browse files
committed
handleJSONResponse should show notifications for each error listed
1 parent 86b2ebe commit 150aede

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

app/assets/javascripts/qpixel_api.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,24 @@ window.QPixel = {
430430
},
431431

432432
handleJSONResponse: (data, onSuccess, onFinally) => {
433-
const is_modified = data.status === 'modified';
434-
const is_success = data.status === 'success';
433+
const is_failed = data.status === 'failed';
435434

436-
if (is_modified || is_success) {
437-
onSuccess(/** @type {Parameters<typeof onSuccess>[0]} */(data));
435+
if(is_failed) {
436+
if (data.message) {
437+
QPixel.createNotification('danger', data.message);
438+
}
439+
440+
for (const error of data.errors ?? []) {
441+
QPixel.createNotification('danger', error);
442+
}
438443
}
439444
else {
440-
QPixel.createNotification('danger', data.message);
445+
onSuccess(/** @type {Parameters<typeof onSuccess>[0]} */(data));
441446
}
442447

443448
onFinally?.(data);
444449

445-
return is_success;
450+
return !is_failed;
446451
},
447452

448453
flag: async (flag) => {

0 commit comments

Comments
 (0)