Permalink
Browse files

Implemented better error handling and reporting as well as a simple h…

…elper for generating a URL to given resource.
  • Loading branch information...
1 parent b3dd413 commit cb6ed9dadcb266ef5bde4891fc72c03b9aff050e @mtodd committed Aug 12, 2009
Showing with 10 additions and 6 deletions.
  1. +10 −6 lib/fuck/resource.rb
View
16 lib/fuck/resource.rb
@@ -9,13 +9,13 @@ def initialize(id, params)
end
def call(env)
- send((find_method(env["REQUEST_METHOD"]) || :not_implemented), *[@id].compact) or
- not_found
- rescue NoMethodError => e
- not_implemented
+ @env = env
+ request_method = find_method(@env["REQUEST_METHOD"]) || :not_implemented
+ return not_implemented unless self.respond_to?(request_method)
+ send(request_method, *[@id].compact) or not_found
rescue Exception => e
- # logger.error e.message
- # logger.error "\t"+e.backtrace.join("\n\t")
+ @env['rack.errors'].puts "ERROR: %s" % e.message
+ @env['rack.errors'].puts "\t%s" % e.backtrace.join("\n\t")
respond("Internal Server Error", :status => 500)
end
@@ -38,6 +38,10 @@ def find_method(request_method)
end
end
+ def location_for(id)
+ "%s://%s/%s" % [@env["rack.url_scheme"], @env["HTTP_HOST"], [self.class.to_s.downcase, id].join('/')]
+ end
+
def params
@params
end

0 comments on commit cb6ed9d

Please sign in to comment.