lib/sapience/error_handler/sentry.rb in sapience-2.0.5 vs lib/sapience/error_handler/sentry.rb in sapience-2.1.0
- old
+ new
@@ -35,17 +35,26 @@
def valid?
sentry_dsn =~ URI_REGEXP
end
def capture_exception(exception, payload = {})
- capture(exception, payload)
+ capture_type(exception, payload)
end
def capture_message(message, payload = {})
- capture(message, payload)
+ capture_type(message, payload)
end
+ def user_context(options = {})
+ Raven.user_context(options)
+ end
+
+ def tags_context(options = {})
+ Raven.tags_context(options)
+ end
+ alias_method :tags=, :tags_context
+
def configured?
@configured == true
end
def configure_sentry
@@ -56,12 +65,45 @@
config.logger = sentry_logger
end
@configured = true
end
+ # Capture, process and reraise any exceptions from the given block.
+ #
+ # @example
+ # Raven.capture do
+ # MyApp.run
+ # end
+ def capture!(options = {})
+ fail ArgumentError unless block_given?
+
+ begin
+ yield
+ rescue StandardError => e
+ capture_type(e, options)
+ raise
+ end
+ end
+
+ # Capture, process and not reraise any exceptions from the given block.
+ #
+ # @example
+ # Raven.capture do
+ # MyApp.run
+ # end
+ def capture(options = {})
+ fail ArgumentError unless block_given?
+
+ begin
+ yield
+ rescue StandardError => e
+ capture_type(e, options)
+ end
+ end
+
private
- def capture(data, payload)
+ def capture_type(data, payload)
return false unless valid?
configure_sentry
options = payload[:extra] ? payload : { extra: payload }