From 3205916aeb04d4c1d065576a7a58ef8c88b39df8 Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Mon, 26 Aug 2019 15:24:14 -0700 Subject: [PATCH] Return 500 error instead of 400 when request is OK but underlying data is bad Fixes #331 --- app/controllers/objects_controller.rb | 2 +- spec/controllers/objects_controller_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/objects_controller.rb b/app/controllers/objects_controller.rb index 97cc3ebf7..768250f04 100644 --- a/app/controllers/objects_controller.rb +++ b/app/controllers/objects_controller.rb @@ -12,7 +12,7 @@ class ObjectsController < ApplicationController end rescue_from(DublinCoreService::CrosswalkError) do |e| - render status: 400, plain: e.message + render status: 500, plain: e.message end # Register new objects in DOR diff --git a/spec/controllers/objects_controller_spec.rb b/spec/controllers/objects_controller_spec.rb index 27e15a494..f9b2dbaef 100644 --- a/spec/controllers/objects_controller_spec.rb +++ b/spec/controllers/objects_controller_spec.rb @@ -62,10 +62,10 @@ context 'with bad metadata' do let(:error_message) { "DublinCoreService#ng_xml produced incorrect xml (no children):\n" } - it 'returns a 400 error' do + it 'returns a 500 error' do allow(PublishMetadataService).to receive(:publish).and_raise(DublinCoreService::CrosswalkError, error_message) post :publish, params: { id: item.pid } - expect(response.status).to eq(400) + expect(response.status).to eq(500) expect(response.body).to eq(error_message) end end