Where to define custom error types in Ruby and/or Rails?
in rails you can make app/errors
directory
# app/errors/foo_error.rb
class FooError < StandardError; end
restart spring/server and it should pick it up
For Gems
I have seen many times that you define exceptions in this way:
gem_dir/lib/gem_name/exceptions.rb
and defined as:
module GemName
class AuthenticationError < StandardError; end
class InvalidUsername < AuthenticationError; end
end
an example of this would be something like this in httparty
For Ruby on Rails
Put them in your lib/ folder under a file called exceptions.rb, which would look something like this:
module Exceptions
class AuthenticationError < StandardError; end
class InvalidUsername < AuthenticationError; end
end
and you would use it like this:
raise Exceptions::InvalidUsername