4

我想在本地(開發)測試異常通知程序。這裏是我的當前設置:Rails 4 +異常通知程序不會以開發模式發送電子郵件

development.rb

Myapp::Application.configure do 
    # Set Mailer default url 
    config.action_mailer.perform_deliveries = true 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' } 
    #config.action_mailer.delivery_method = :file 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
     :address    => 'smtp.gmail.com', 
     :port     => 587, 
     :domain    => 'gmail.com', 
     :user_name   => '[email protected]', 
     :password    => 'password', 
     :authentication  => 'plain', 
     :enable_starttls_auto => true 
    } 

    config.middleware.use ExceptionNotification::Rack, 
    :email => { 
     :email_prefix => "[Myapp Error] ", 
     :sender_address => %{"notifier" <[email protected]>}, 
     :exception_recipients => %w{[email protected]} 
    } 
end 

但在應用時,我「創造」的錯誤 - 例如,如果我設置了不存在的ID,如

http://localhost:3000/users/12270/edit 

我只能在瀏覽器中看到錯誤,但不發送電子郵件(電子郵件憑據是正確的)。

我錯過了什麼?

比你

回答

1

要禁用發展模式下的錯誤頁面,您還需要設置:

config.consider_all_requests_local = false 
1

ExceptionNotifier將在500錯誤發送消息。但是,您的測試「...如果我請求一個不存在的ID ...」返回404找不到。 From the docs

一些機架應用程序(滑軌具體地)利用「X-級聯」頭到 傳入 堆疊中的請求處理責任到下一個中​​間件。 Rails的路由中間件使用這種策略,而不是引發異常,以處理路由錯誤(例如404s)。每當發生404時都要通知 ,請將此選項設置爲「false」。

相關問題