Handle timeouts inside a view for API calls
This commit is contained in:
parent
f138055849
commit
d1d3c2597e
1 changed files with 10 additions and 0 deletions
|
@ -178,6 +178,16 @@ class ApiController < ApplicationController
|
|||
# wrap an api call in a timeout
|
||||
def api_call_timeout(&block)
|
||||
Timeout.timeout(Settings.api_timeout, Timeout::Error, &block)
|
||||
rescue ActionView::Template::Error => e
|
||||
e = e.cause
|
||||
|
||||
if e.is_a?(Timeout::Error) ||
|
||||
(e.is_a?(ActiveRecord::StatementInvalid) && e.message.include?("execution expired"))
|
||||
ActiveRecord::Base.connection.raw_connection.cancel
|
||||
raise OSM::APITimeoutError
|
||||
else
|
||||
raise
|
||||
end
|
||||
rescue Timeout::Error
|
||||
ActiveRecord::Base.connection.raw_connection.cancel
|
||||
raise OSM::APITimeoutError
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue