BetterErrors / better_errors

Better error page for Rack apps
MIT License
6.88k stars 437 forks source link

allow custom favicon #362

Open psimyn opened 7 years ago

psimyn commented 7 years ago

we have some pages that use a different favicon (or non .ico icons)

I think custom path might be the way to go, since that favicon caches are super long

Many thanks for such great errors

RobinDaugherty commented 7 years ago

Can you explain the purpose of supporting favicons? Since this is a development-only tool, it doesn't seem like that would be useful.

psimyn commented 7 years ago

We currently use different coloured favicons for dev vs prod environments. Helps distinguish which window is which when there are many tabs open. This shows production (left), tab with error, and tab with dev favicon. Ideally the one in the middle should be green

screen shot 2017-08-01 at 10 36 56 am
RobinDaugherty commented 7 years ago

Okay, I can see the value in it being obvious whether you are on production 😬. It seems an edge case, but it also seems like an easy thing to add. Perhaps the default icon should be some kind of Better Errors icon.

coezbek commented 7 months ago

I just wanted to see my usual favicon for the app so I can find the browser tab, so I did the following to to override the main.erb template in an initializer:

module BetterErrors
  # @private
  class ErrorPage
    class <<self
      alias_method :original_template_path, :template_path
    end

    def self.template_path(template_name)
      if template_name == "main"
        File.expand_path("../../../lib/better_errors/templates/#{template_name}.erb", __FILE__)
      else
        original_template_path(template_name) 
      end
    end
  end
end

The template I just overrode in place of the favicon (and saved in lib/better_errors/templates/main.erb):

<!DOCTYPE html>
<html>
<head>
    <title><%= exception_type %> at <%= request_path %></title>
    <link rel="icon" type="image/png" href="/favicon.png">
</head>
...