Skip to content

Commit

Permalink
Merge pull request #10 from localytics/timeout-errors
Browse files Browse the repository at this point in the history
Manually rescue timeout errors
  • Loading branch information
kddnewton authored Feb 9, 2017
2 parents 746712b + 363d55f commit ca793ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/active_record/connection_adapters/odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
require 'arel/visitors/bind_visitor'
require 'odbc'

require 'odbc_adapter'
require 'odbc_adapter/database_limits'
require 'odbc_adapter/database_statements'
require 'odbc_adapter/error'
require 'odbc_adapter/quoting'
require 'odbc_adapter/schema_statements'

Expand Down Expand Up @@ -76,7 +76,9 @@ class ODBCAdapter < AbstractAdapter

ADAPTER_NAME = 'ODBC'.freeze
BOOLEAN_TYPE = 'BOOLEAN'.freeze

ERR_DUPLICATE_KEY_VALUE = 23505
ERR_QUERY_TIMED_OUT = /Query has timed out/

attr_reader :database_metadata

Expand Down Expand Up @@ -166,9 +168,11 @@ def initialize_type_map(map)
end

def translate_exception(exception, message)
case exception.message[/^\d+/].to_i
when ERR_DUPLICATE_KEY_VALUE
case
when exception.message[/^\d+/].to_i == ERR_DUPLICATE_KEY_VALUE
ActiveRecord::RecordNotUnique.new(message, exception)
when exception.message =~ ERR_QUERY_TIMED_OUT
::ODBCAdapter::QueryTimeoutError.new(message, exception)
else
super
end
Expand Down
4 changes: 4 additions & 0 deletions lib/odbc_adapter/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ODBCAdapter
class QueryTimeoutError < ActiveRecord::StatementInvalid
end
end
2 changes: 1 addition & 1 deletion lib/odbc_adapter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ODBCAdapter
VERSION = '5.0.0'
VERSION = '5.0.1'
end

0 comments on commit ca793ff

Please sign in to comment.