Sha256: a333c5c3bb7eadadbd145122b7837fb78dc770a3c7495a98566e0a422a711afc

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module PublishMyData
  class ApplicationController < ActionController::Base

    # Note: this order matters. Perversely, need to put more general errors first.
    rescue_from Exception, :with => :handle_uncaught_error
    rescue_from Tripod::Errors::ResourceNotFound, :with => :handle_resource_not_found
    rescue_from RestClient::RequestTimeout, :with => :handle_timeout

    private

    # TODO: deal with javaascript errors - respond with 200

    def handle_uncaught_error(e)
      @e = e
      Raven.capture_exception(e) if defined?(Raven) # TODO: move this out of the CE.
      Rails.logger.info "***UNCAUGHT ERROR***"
      Rails.logger.info e.class.name
      Rails.logger.info e.message
      Rails.logger.info e.backtrace.join("\n")
      respond_to do |format|
        format.html { render(:template => "publish_my_data/errors/uncaught", :layout => 'publish_my_data/error', :status => 500) and return false }
        format.any{ head(:status => 500, :content_type => 'text/plain') and return false }
      end

    end

    def handle_timeout(e)
      respond_to do |format|
        format.html { render(:template => "publish_my_data/errors/timeout", :layout => 'publish_my_data/error', :status => 503) and return false }
        format.any { head(:status => 503, :content_type => 'text/plain') and return false }
      end
    end

    def handle_resource_not_found(e)
      respond_to do |format|
        format.html { render(:template => "publish_my_data/errors/not_found", :layout => 'publish_my_data/error', :status => 404) and return false }
        format.any { head(:status => 404, :content_type => 'text/plain') and return false }
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
publish_my_data-0.0.10 app/controllers/publish_my_data/application_controller.rb