extracted exception management in errors.rb like ActiveRecord does