More details on posts and error reporting

This commit is contained in:
2023-05-31 22:12:48 +10:00
parent b034ecb3ab
commit 2c1122c9d7
20 changed files with 177 additions and 39 deletions

View File

@@ -9,12 +9,17 @@ require "dry/matcher/result_matcher"
module Adamantium
class Action < Hanami::Action
include Deps["logger", "settings", not_found_view: "views.not_found"]
include Deps["logger",
"settings",
not_found_view: "views.not_found",
error_view: "views.error",
sentry: "sentry.client"]
include Dry::Matcher.for(:handle, with: Dry::Matcher::ResultMatcher)
include Dry::Monads[:result]
handle_exception ROM::TupleCountMismatchError => :not_found
handle_exception StandardError => :handle_error
def authenticate!(req, res)
if Hanami.env == :development || Hanami.env == :test
@@ -47,6 +52,16 @@ module Adamantium
res.render not_found_view
end
def handle_error(req, res, exception)
raise exception if settings.raise_exceptions
sentry.capture_exception(exception)
res.status = 500
res.render error_view
res.headers["Cache-Control"] = "no-store, max-age=0"
end
def verify_scope(req:, scope:)
req.env[:scopes].include? scope
end