Created
April 3, 2013 14:20
-
-
Save sycobuny/5301627 to your computer and use it in GitHub Desktop.
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 MyApp | |
class APIError < Exception; end | |
class Web < Sinatra::Base | |
def self.api(&block) | |
# some crazy stuff to wrap any get/put/delete/post/patch | |
# requests into a block with automatic error handling, and | |
# pass on all other requests to the sinatra base class. | |
end | |
api do | |
get '/hi' do | |
raise APIError, "Not implemented!" | |
end | |
put '/hi' do | |
raise APIError, "Not implemented!" | |
end | |
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 MyApp | |
class APIError < Exception; end | |
class Web < Sinatra::Base | |
get '/hi' do | |
raise APIError, "Not implemented!" | |
rescue APIError => e | |
json :ok => false, :message => e.to_s | |
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 MyApp | |
class APIError < Exception; end | |
class Web < Sinatra::Base | |
error APIError do | |
json :ok => false, :message => env['whatever the exception key is'].to_s | |
end | |
get '/hi' do | |
raise APIError, "Not implemented!" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment