Permalink
Browse files

Added some error checking for JSON and HTTP errors (STILL NEED TESTS)

  • Loading branch information...
1 parent faf5668 commit efc4a12d6d69f33a3268ff205dc1220a70c6189d harrisj committed Aug 19, 2008
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/active_record/connection_adapters/dbslayer_connection.rb
View
10 lib/active_record/connection_adapters/dbslayer_connection.rb
@@ -82,8 +82,14 @@ def initialize(host='localhost', port=9090)
##
# Executes a SQL query
def sql_query(sql)
- dbslay_results = cmd_execute(:db, 'SQL' => sql)
-
+ begin
+ dbslay_results = cmd_execute(:db, 'SQL' => sql)
+ rescue OpenURI::HTTPError
+ raise DbslayerException, "Error connecting to dbslayer #{host}:#{port}"
+ rescue JSON::ParserError
+ raise DbslayerException, "Unable to parse result from JSON"
+ end
+
# check for an error
if dbslay_results['MYSQL_ERROR']
raise DbslayerException, "MySQL Error #{dbslay_results['MYSQL_ERRNO']}: #{dbslay_results['MYSQL_ERROR']}"

0 comments on commit efc4a12

Please sign in to comment.