Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #916 from dmann/DDS-809-fix_request_timeout-develop
Browse files Browse the repository at this point in the history
DDS-809 fix request timeout develop
  • Loading branch information
dmann committed Feb 15, 2017
2 parents db30905 + d2eb91e commit 6501b07
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/api/dds/v1/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ def get_auth_service(service_id = nil)
},401)
end

rescue_from Rack::Timeout::RequestTimeoutError do |e|
error_json = {
"error" => "503",
"reason" => 'Request Timeout',
"suggestion" => 'try again in a few minutes, or contact the systems administrators'
}
error!(error_json, 503)
end

mount DDS::V1::UsersAPI
mount DDS::V1::SystemPermissionsAPI
mount DDS::V1::AppAPI
Expand Down
36 changes: 36 additions & 0 deletions spec/requests/base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'rails_helper'

describe DDS::V1::Base do
let(:path) {"/api_base_test"}
let(:dummy) do
dummy_path = path
Class.new(Grape::API) do
helpers do
def override_helper; end
end
get dummy_path do
override_helper
end
end
end
before do
described_class.mount dummy
DDS::Base.change!
end

let(:url) {"/api/v1" + path }
subject { get(url) }

context 'when Rack::Timeout raises Rack::Timeout::RequestTimeoutError' do
before do
Grape::Endpoint.before_each do |endpoint|
expect(endpoint).to receive(:override_helper).and_raise(Rack::Timeout::RequestTimeoutError, ENV)
end
end
after { Grape::Endpoint.before_each nil }
it 'should return a 503' do
is_expected.to eq 503
expect(response.body).to include('Request Timeout')
end
end
end

0 comments on commit 6501b07

Please sign in to comment.