diff --git a/README.md b/README.md index 59e3542..8ac9d20 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ This method requires a resource as a parameter, and you can pass some options if The above example will render the **User** object. user = User.first - respond_with user, on_error: { + respond_with user, on_error: { : :unauthorized, detail: 'Invalid user or password' } The above example will render an **Error** response if an error would occur. @@ -120,7 +120,7 @@ en: forbidden: title: Unauthorized detail: User is not authorized to use this resource - unprocessable_entity: + unprocessable_content: title: Unprocessable Entity details: Cannot process request conflict: diff --git a/lib/json_api_responders.rb b/lib/json_api_responders.rb index d307972..01b78ff 100644 --- a/lib/json_api_responders.rb +++ b/lib/json_api_responders.rb @@ -40,7 +40,7 @@ def record_not_found!(reason) end def parameter_missing!(reason) - respond_with_error(:unprocessable_entity, reason.message) + respond_with_error(:unprocessable_content, reason.message) end def json_api_parse_options diff --git a/lib/json_api_responders/responder/actions.rb b/lib/json_api_responders/responder/actions.rb index ff34270..32fcf3b 100644 --- a/lib/json_api_responders/responder/actions.rb +++ b/lib/json_api_responders/responder/actions.rb @@ -15,7 +15,7 @@ def respond_to_show_action def respond_to_create_action if has_errors? - self.status ||= :unprocessable_entity + self.status ||= :unprocessable_content render_error else self.status ||= :created @@ -25,7 +25,7 @@ def respond_to_create_action def respond_to_update_action if has_errors? - self.status ||= :unprocessable_entity + self.status ||= :unprocessable_content render_error else self.status ||= :ok diff --git a/spec/lib/json_api_responders/responder/actions_spec.rb b/spec/lib/json_api_responders/responder/actions_spec.rb index 08e10a7..8bae630 100644 --- a/spec/lib/json_api_responders/responder/actions_spec.rb +++ b/spec/lib/json_api_responders/responder/actions_spec.rb @@ -16,7 +16,7 @@ json: { errors: [ { - title: 'json_api.errors.unprocessable_entity.title', + title: 'json_api.errors.unprocessable_content.title', detail: "Name can't be blank", source: { parameter: :name, pointer: 'data/attributes/name' } } @@ -60,9 +60,9 @@ end context 'when resource invalid' do - let(:status) { :unprocessable_entity } + let(:status) { :unprocessable_content } - it 'renders unprocessable_entity' do + it 'renders unprocessable_content' do expect(controller).to receive(:render).with(error_options) responder.respond! end @@ -83,9 +83,9 @@ end context 'when resource invalid' do - let(:status) { :unprocessable_entity } + let(:status) { :unprocessable_content } - it 'renders unprocessable_entity' do + it 'renders unprocessable_content' do expect(controller).to receive(:render).with(error_options) responder.respond! end @@ -149,9 +149,9 @@ end context 'when resource invalid' do - let(:status) { :unprocessable_entity } + let(:status) { :unprocessable_content } - it 'renders unprocessable_entity' do + it 'renders unprocessable_content' do expect(controller).to receive(:render).with(error_options) responder.respond! end @@ -172,9 +172,9 @@ end context 'when resource invalid' do - let(:status) { :unprocessable_entity } + let(:status) { :unprocessable_content } - it 'renders unprocessable_entity' do + it 'renders unprocessable_content' do expect(controller).to receive(:render).with(error_options) responder.respond! end diff --git a/spec/lib/json_api_responders_spec.rb b/spec/lib/json_api_responders_spec.rb index 160c4e4..7546b92 100644 --- a/spec/lib/json_api_responders_spec.rb +++ b/spec/lib/json_api_responders_spec.rb @@ -46,7 +46,7 @@ content_type: 'application/vnd.api+json', json: { errors: [ { detail: 'Unauthorized' }, - { title: 'json_api.errors.unprocessable_entity.title', + { title: 'json_api.errors.unprocessable_content.title', detail: "Name can't be blank", source: { parameter: :name, pointer: 'data/attributes/name' } } ] }