Created
August 1, 2020 14:11
-
-
Save psylone/11ecee906a10951284dca3c42dab6b53 to your computer and use it in GitHub Desktop.
Roda errors handler in separate file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'errors' | |
class App < Roda | |
plugin :error_handler | |
include Errors | |
route do |r| | |
r.root do | |
raise ArgumentError | |
'root' | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Errors | |
def self.included(base) | |
base.error do |e| | |
handle_errors(e) | |
end | |
end | |
private | |
def handle_errors(e) | |
case e | |
when ArgumentError | |
'argument error' | |
else | |
'runtime error' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment