Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge commit '74e943a861f6e3ff71eeee07f5f7bcf7acf797c6' into HEAD

  • Loading branch information...
commit 91c55c5bd3eaf594230057faed47d2c4f780968a 2 parents 1fccf05 + 74e943a
Jenkins authored
View
1  Gemfile
@@ -5,6 +5,7 @@ gem "zendesk_api"
gem "rake"
gem "unicorn"
gem 'slimmer', '1.2.4'
+gem "mail"
group :test do
gem "rack-test"
View
10 Gemfile.lock
@@ -12,11 +12,16 @@ GEM
null_logger
plek
hashie (1.2.0)
+ i18n (0.6.1)
inflection (1.0.0)
json (1.7.5)
kgio (2.7.4)
lrucache (0.1.3)
PriorityQueue (~> 0.1.2)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
metaclass (0.0.1)
mime-types (1.19)
mocha (0.12.3)
@@ -26,6 +31,7 @@ GEM
null_logger (0.0.1)
plek (0.3.0)
builder
+ polyglot (0.3.3)
rack (1.4.1)
rack-protection (1.2.0)
rack
@@ -45,6 +51,9 @@ GEM
plek (>= 0.1.8)
rack (>= 1.3.5)
tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
unicorn (4.3.1)
kgio (~> 2.6)
rack
@@ -62,6 +71,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ mail
mocha
rack-test
rake
View
1  config/mailer.yml
View
32 lib/app.rb
@@ -5,6 +5,7 @@
require_relative "zendesk_request"
require_relative "zendesk_error"
require_relative "validations"
+require_relative "exception_mailer"
class App < Sinatra::Base
@@ -16,6 +17,10 @@ class App < Sinatra::Base
before do
@client = ZendeskClient.get_client(logger)
+
+ #if @client.current_user["id"].nil?
+ # raise ZendeskError.new("Authentication error", "Check logs for details")
+ #end
end
get '/' do
@@ -30,7 +35,7 @@ class App < Sinatra::Base
erb :fail
end
- # Content routing
+ #Content routing
get '/amend-content' do
on_get("Content Change", "content/content_amend_message", "content/amend")
end
@@ -44,7 +49,7 @@ class App < Sinatra::Base
on_post(params, "amend-content")
end
-# User access routing
+ #User access routing
get '/create-user' do
on_get("Create New User", "useraccess/user_create_message", "useraccess/user")
end
@@ -145,6 +150,7 @@ def on_post(params, route)
if ticket
redirect '/acknowledge'
else
+ ExceptionMailer.deliver_exception_notification(env['sinatra.error'])
redirect '/failed-submission'
end
else
@@ -153,12 +159,30 @@ def on_post(params, route)
end
error do
- @error_msg = "And error IS: #{request.env['sinatra.error']}"
+ ExceptionMailer.deliver_exception_notification(env['sinatra.error'])
+ @error_msg = request.env['sinatra.error']
erb :error_page
end
error ZendeskError do
- redirect '/failed-submission'
+ exception_message = format_exception_message(env['sinatra.error'].message, env['sinatra.error'].details_from_zendesk)
+ ExceptionMailer.deliver_exception_notification(exception_message)
+
+ redirect "/failed-submission"
+ end
+
+ def format_exception_message(message, details)
+ time = Time.now
+ message = <<-EOF
+ At #{time}
+ Error
+ #{message}
+
+ Zendesk responded with:
+ #{details}
+ EOF
+
+ message
end
end
View
21 lib/exception_mailer.rb
@@ -0,0 +1,21 @@
+require 'mail'
+require 'yaml'
+
+class ExceptionMailer
+ def self.deliver_exception_notification(message)
+ mailer_file = YAML.load_file("config/mailer.yml")
+ environment = ENV['GOVUK_ENV'] || "development"
+
+ Mail.deliver do
+ delivery_method :smtp, {
+ :address => "smtp.gmail.com", :port => 587, :domain => 'alphagov.co.uk',
+ :user_name => mailer_file[environment]["username"].to_s, :password => mailer_file[environment]["password"].to_s, :authentication => 'plain',
+ :enable_starttls_auto => true
+ }
+ from 'Winston Smith-Churchill <winston@alphagov.co.uk>'
+ to 'govuk-exceptions@digital.cabinet-office.gov.uk'
+ subject "Zendesk MI5-minesweeper has blown"
+ body message
+ end
+ end
+end
View
4 lib/zendesk_client.rb
@@ -21,13 +21,13 @@ def self.get_client(logger)
logger.info env
if env[:body]["user"]
if env[:body]["id"].nil?
- raise ZendeskError.new("Authentication Error")
+ raise ZendeskError.new("Authentication Error", env)
end
end
status_401 = env[:status].to_s.start_with? "401"
too_many_login_attempts = env[:body].to_s.start_with? "Too many failed login attempts"
if status_401 || too_many_login_attempts
- raise ZendeskError.new("Authentication Error")
+ raise ZendeskError.new("Authentication Error", env)
end
end
View
5 lib/zendesk_error.rb
@@ -1,9 +1,10 @@
class ZendeskError < StandardError
- attr_reader :message
+ attr_reader :message, :details_from_zendesk
- def initialize(message)
+ def initialize(message, details_from_zendesk)
@message = message.to_s
+ @details_from_zendesk = details_from_zendesk
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.