Check for existence of failed events before redelivering

This commit is contained in:
Arpit Jalan 2024-06-14 14:32:17 +05:30
parent 500e26d1fe
commit 77408b8ea2
2 changed files with 11 additions and 2 deletions

View File

@ -129,6 +129,11 @@ export default class WebhookEvents extends Component {
this.eventIds = this.events.content.map((event) => event.id);
this.count = this.events.length;
if (this.count === 0) {
this.dialog.alert("No events to redeliver.");
return;
}
return this.dialog.yesNoConfirm({
message: I18n.t("admin.web_hooks.events.bulk_redeliver_confirm", {
count: this.count,
@ -139,7 +144,11 @@ export default class WebhookEvents extends Component {
`/admin/api/web_hooks/${this.args.webhookId}/events/bulk_redeliver`,
{ type: "POST", data: { event_ids: this.eventIds } }
);
this.args.event.setProperties(json.web_hook_event);
if (json.web_hook_event && json.web_hook_event.length > 0) {
this.args.event.setProperties(json.web_hook_event);
} else {
this.dialog.alert("No events to redeliver.");
}
} catch (e) {
popupAjaxError(e);
}

View File

@ -138,7 +138,7 @@ class Admin::WebHooksController < Admin::AdminController
def bulk_redeliver_events
limit = 50
offset = params[:offset].to_i
failed_events = @web_hook.web_hook_events.failed.limit(limit).offset(offset)
failed_events = @web_hook&.web_hook_events&.failed&.limit(limit)&.offset(offset)
render_serialized(failed_events, AdminWebHookEventSerializer, root: "web_hook_event")
end