Skip to content

Commit 9c58e6e

Browse files
committed
Use ActionDispatch::Request for path checking
The `PublicExceptions` middleware is used on _every_ request. It doesn't make sense to create JSON API specific request objects for requests that are _not_ part of a JSON API route. Instead we should only create those requests _after_ we've already confirmed we are working with a JSON API request. Along these lines we should only be checking the path to see if it is a pre-determined JSON API resource. Further mime type negotiation / validation should be handled by the final endpoint. I'm not sure why we did the format check here initially; I can only think that it was meant to be more "generic" and possibly allow multiple content types but only wrap errors for JSON API content. However, our current endpoints are JSON API only and clients would likely expect JSON API errors for any problems when accessing them.
1 parent 46dacca commit 9c58e6e

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/kracken/json_api/path.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def initialize(path)
1010
end
1111

1212
def matches?(request)
13-
request.supports_json_format? && path_matches?(request.path)
13+
path_matches?(request.original_fullpath)
1414
end
1515

1616
private

lib/kracken/json_api/public_exceptions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def initialize(app)
3737
end
3838

3939
def call(env)
40-
if JsonApi.has_path?(JsonApi::Request.new(env))
40+
if JsonApi.has_path?(ActionDispatch::Request.new(env))
4141
capture_error(env)
4242
else
4343
@app.call(env)

0 commit comments

Comments
 (0)