-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1309 from BigG1947/send-sentry-when-csv-download-…
…failed-with-exception send sentry when csv download failed with exception
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveAdmin | ||
module CsvStreamWithErrorHandler | ||
protected | ||
|
||
def stream_resource(&) | ||
block_with_error_handler = wrap_stream_error_handling(&) | ||
super(&block_with_error_handler) | ||
end | ||
|
||
private | ||
|
||
# When we stream response block is executed in Puma after rails done with request. | ||
# All exceptions are rescued and suppressed. | ||
def wrap_stream_error_handling | ||
error_context = capture_context | ||
proc do |csv| | ||
yield(csv) | ||
rescue StandardError => e | ||
CaptureError.log_error(e) | ||
CaptureError.capture(e, error_context) | ||
raise e | ||
end | ||
end | ||
end | ||
end |