Skip to content

Commit 9a06090

Browse files
committed
Return a 404 response when no record is found
The JSON API specification says: > A server MUST respond with `404 Not Found` when processing a request to fetch a single resource that does not exist At the moment JSON API Resources returns a 200, with an empty data object.
1 parent c0cdf65 commit 9a06090

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/jsonapi/processor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def show
101101
include_directives,
102102
find_options)
103103

104+
fail JSONAPI::Exceptions::RecordNotFound.new(id) if resource_set.resource_klasses.empty?
104105
resource_set.populate!(serializer, context, find_options)
105106

106107
return JSONAPI::ResourceSetOperationResult.new(:ok, resource_set, result_options)

test/integration/requests/request_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def test_large_get
2525
assert_cacheable_jsonapi_get '/api/v2/books?include=book_comments,book_comments.author'
2626
end
2727

28+
def test_get_not_found
29+
get "/people/2000"
30+
assert_jsonapi_response 404
31+
end
32+
2833
def test_post_sessions
2934
session_id = SecureRandom.uuid
3035

0 commit comments

Comments
 (0)