Class: NoBrainer::QueryRunner::WriteError
- Inherits:
-
Middleware
- Object
- Middleware
- NoBrainer::QueryRunner::WriteError
- Defined in:
- lib/no_brainer/query_runner/write_error.rb
Instance Method Summary collapse
Methods inherited from Middleware
Constructor Details
This class inherits a constructor from NoBrainer::QueryRunner::Middleware
Instance Method Details
#call(env) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/no_brainer/query_runner/write_error.rb', line 2 def call(env) write_query = NoBrainer::RQL.is_write_query?(env[:query]) @runner.call(env).tap do |result| if write_query && (result['errors'].to_i != 0) error_msg = result['first_error'] raise_write_error(env, error_msg) end end rescue RethinkDB::RqlRuntimeError => e raise unless write_query error_msg = e..split("\nBacktrace").first error_msg = "Non existent document" if e. =~ /Expected type OBJECT but found NULL/ raise_write_error(env, error_msg) end |