ruby版本2.3.0
rails版本5.0.0.beta2
**GEMFILE**
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '>= 5.0.0.beta2', '< 5.1'
#mongoid gem
gem 'mongoid', '~> 5.1.0'
# Use Puma as the app server
gem 'puma'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby …Run Code Online (Sandbox Code Playgroud) 我使用 postgres 和 knex javascript 库来构建我的 sql 查询。我想处理来自 postgres 服务器的所有抛出的错误,因此我想要执行此操作的方法是检查抛出的错误的类型。
try {
// knex query here
} catch(error) {
if(error instanceof DatabaseError) {
// handle pg error by checking error.code or something else
// then send an custom error message to the client
}
// handle another error here which is not caused by the postgres server
}
Run Code Online (Sandbox Code Playgroud)
有什么办法可以处理这样的错误吗?