Created
November 4, 2008 18:24
-
-
Save croaky/22180 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
| HTTP_ERRORS = [Timeout::Error, | |
| Errno::EINVAL, | |
| Errno::ECONNRESET, | |
| EOFError, | |
| Net::HTTPBadResponse, | |
| Net::HTTPHeaderSyntaxError, | |
| Net::ProtocolError] | |
| SMTP_SERVER_ERRORS = [TimeoutError, | |
| IOError, | |
| Net::SMTPUnknownError, | |
| Net::SMTPServerBusy, | |
| Net::SMTPAuthenticationError] | |
| SMTP_CLIENT_ERRORS = [Net::SMTPFatalError, | |
| Net::SMTPSyntaxError] | |
| SMTP_ERRORS = SMTP_SERVER_ERRORS + SMTP_CLIENT_ERRORS | |
| # usage | |
| class ApplicationController < ActionController::Base | |
| rescue_from *SMTP_SERVER_ERRORS, :with => :smtp_server_error | |
| rescue_from *SMTP_CLIENT_ERRORS, :with => :smtp_client_error | |
| rescue_from *SMTP_ERRORS do |error| | |
| notify_hoptoad error | |
| end | |
| protected | |
| def smtp_server_error | |
| flash[:warning] = "We encountered an internal issue while " << | |
| "attempting to deliver this email. " << | |
| "Please try again in a few minutes." | |
| render :action => :new | |
| end | |
| def smtp_client_error | |
| flash[:warning] = "The email address supplied is invalid. " << | |
| "Please check for spelling mistakes." | |
| render :action => :new | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment