Consolidate middleware in Roda
RewindableInput middleware enables Sentry to automatically capture
request bodies, removing the need for manual body reading.
Assisted-by: Claude Opus 4.5 via Claude Code
diff --git a/config.ru b/config.ru
index 1e73f99..7de5d55 100644
--- a/config.ru
+++ b/config.ru
@@ -1,8 +1,5 @@
# frozen_string_literal: true
-require "sentry-ruby"
-use Sentry::Rack::CaptureExceptions
-
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
require "pro_tacts/web"
diff --git a/lib/pro_tacts/web.rb b/lib/pro_tacts/web.rb
index bd6ec4e..b28eb4c 100644
--- a/lib/pro_tacts/web.rb
+++ b/lib/pro_tacts/web.rb
@@ -17,21 +17,24 @@ Sentry.init do |config|
config.traces_sample_rate = 1.0
end
+require "rack/rewindable_input"
require "roda"
require "roda/plugins/dav_verbs"
module ProTacts
class Web < Roda
+ # RewindableInput allows us to read the request body for Sentry logging
+ # and then rewind it so the application can still access it.
+ use Rack::RewindableInput::Middleware
+ use Sentry::Rack::CaptureExceptions
+
plugin :all_verbs
plugin :dav_verbs
+ plugin :common_logger
plugin :not_found do
- Sentry.capture_message("404 Not Found", level: :warning, extra: {
- path: request.path,
- method: request.request_method,
- body: request.body.read
- })
+ Sentry.capture_message("404 Not Found", level: :warning)
"Not Found"
end