Skip to content

Commit 561d349

Browse files
authored
Merge pull request #915 from cerebris/revert-914-pr/895
Revert "Pr/895"
2 parents 923a249 + fa07000 commit 561d349

5 files changed

Lines changed: 3 additions & 75 deletions

File tree

lib/jsonapi/error_codes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module JSONAPI
2020
INVALID_FILTERS_SYNTAX = '120'
2121
SAVE_FAILED = '121'
2222
INVALID_DATA_FORMAT = '122'
23-
BAD_REQUEST = '400'
2423
FORBIDDEN = '403'
2524
RECORD_NOT_FOUND = '404'
2625
NOT_ACCEPTABLE = '406'

lib/jsonapi/exceptions.rb

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,32 +119,6 @@ def errors
119119
end
120120
end
121121

122-
class BadRequest < Error
123-
def initialize(exception)
124-
@exception = exception
125-
end
126-
127-
def errors
128-
[JSONAPI::Error.new(code: JSONAPI::BAD_REQUEST,
129-
status: :bad_request,
130-
title: I18n.translate('jsonapi-resources.exceptions.bad_request.title',
131-
default: 'Bad Request'),
132-
detail: I18n.translate('jsonapi-resources.exceptions.bad_request.detail',
133-
default: @exception))]
134-
end
135-
end
136-
137-
class InvalidRequestFormat < Error
138-
def errors
139-
[JSONAPI::Error.new(code: JSONAPI::BAD_REQUEST,
140-
status: :bad_request,
141-
title: I18n.translate('jsonapi-resources.exceptions.invalid_request_format.title',
142-
default: 'Bad Request'),
143-
detail: I18n.translate('jsonapi-resources.exceptions.invalid_request_format.detail',
144-
default: 'Request must be a hash'))]
145-
end
146-
end
147-
148122
class ToManySetReplacementForbidden < Error
149123
def errors
150124
[JSONAPI::Error.new(code: JSONAPI::FORBIDDEN,

lib/jsonapi/mime_types.rb

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'json'
2-
31
module JSONAPI
42
MEDIA_TYPE = 'application/vnd.api+json'
53

@@ -21,18 +19,9 @@ def self.install
2119

2220
def self.parser
2321
lambda do |body|
24-
begin
25-
data = JSON.parse(body)
26-
if data.is_a?(Hash)
27-
data.with_indifferent_access
28-
else
29-
fail JSONAPI::Exceptions::InvalidRequestFormat.new
30-
end
31-
rescue JSON::ParserError => e
32-
{ _parser_exception: JSONAPI::Exceptions::BadRequest.new(e.to_s) }
33-
rescue => e
34-
{ _parser_exception: e }
35-
end
22+
data = JSON.parse(body)
23+
data = {:_json => data} unless data.is_a?(Hash)
24+
data.with_indifferent_access
3625
end
3726
end
3827
end

lib/jsonapi/request_parser.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def setup_action(params)
3434

3535
setup_action_method_name = "setup_#{params[:action]}_action"
3636
if respond_to?(setup_action_method_name)
37-
raise params[:_parser_exception] if params[:_parser_exception]
3837
send(setup_action_method_name, params)
3938
end
4039
rescue ActionController::ParameterMissing => e

test/integration/requests/request_test.rb

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -353,39 +353,6 @@ def test_put_content_type
353353
assert_match JSONAPI::MEDIA_TYPE, headers['Content-Type']
354354
end
355355

356-
def test_put_valid_json
357-
put '/posts/3', params: '{"data": { "type": "posts", "id": "3", "attributes": { "title": "A great new Post" } } }',
358-
headers: {
359-
'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE,
360-
'Accept' => JSONAPI::MEDIA_TYPE
361-
}
362-
363-
assert_equal 200, status
364-
end
365-
366-
def test_put_invalid_json
367-
put '/posts/3', params: '{"data": { "type": "posts", "id": "3" "attributes": { "title": "A great new Post" } } }',
368-
headers: {
369-
'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE,
370-
'Accept' => JSONAPI::MEDIA_TYPE
371-
}
372-
373-
assert_equal 400, status
374-
assert_equal 'Bad Request', json_response['errors'][0]['title']
375-
assert_match 'unexpected token at', json_response['errors'][0]['detail']
376-
end
377-
378-
def test_put_valid_json_but_array
379-
put '/posts/3', params: '[{"data": { "type": "posts", "id": "3", "attributes": { "title": "A great new Post" } } }]',
380-
headers: {
381-
'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE,
382-
'Accept' => JSONAPI::MEDIA_TYPE
383-
}
384-
385-
assert_equal 400, status
386-
assert_equal 'Request must be a hash', json_response['errors'][0]['detail']
387-
end
388-
389356
def test_patch_content_type
390357
patch '/posts/3', params:
391358
{

0 commit comments

Comments
 (0)