Skip to content

Commit a370f64

Browse files
committed
Keep API error contracts in development
1 parent 7a6c065 commit a370f64

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def development? = self.class.development?
9292
plugin :not_allowed
9393
plugin :exception_page
9494
plugin :error_handler do |error|
95-
next exception_page(error) if development? && !error.is_a?(NotFoundError)
95+
next exception_page(error) if development? && !error.is_a?(HttpError)
9696

9797
ErrorResponder.respond(request: request, response: response, error: error)
9898
end

spec/html2rss/web/app_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ def app = described_class
216216
expect(json.dig('error', 'code')).to eq(Html2rss::Web::InternalServerError::CODE)
217217
expect(json.dig('error', 'message')).to eq('Internal Server Error')
218218
end
219+
220+
it 'keeps API auth failures on the JSON error contract in development mode' do
221+
ClimateControl.modify('RACK_ENV' => 'development') do
222+
post '/api/v1/feeds', JSON.generate(url: 'https://example.com/articles'),
223+
{ 'CONTENT_TYPE' => 'application/json', 'HTTP_AUTHORIZATION' => 'Bearer invalid-token' }
224+
end
225+
226+
expect(last_response.status).to eq(401)
227+
expect(last_response.headers['Content-Type']).to include('application/json')
228+
json = JSON.parse(last_response.body)
229+
expect(json.dig('error', 'code')).to eq(Html2rss::Web::UnauthorizedError::CODE)
230+
expect(json.dig('error', 'message')).to eq('Authentication required')
231+
end
219232
end
220233

221234
describe '.development?' do

0 commit comments

Comments
 (0)