Module: Waxx::Error

Defined in:
waxx/error.rb

Overview

Waxx Copyright © 2016 ePark labs Inc. & Daniel J. Fitzpatrick <dan@eparklabs.com> All rights reserved. Released under the Apache Version 2 License. See LICENSE.txt.

Instance Method Summary collapse

Instance Method Details

#error(x, status: 200, type: nil, title: "An error occurred", message: "", args: []) ⇒ Object



5
6
7
8
# File 'waxx/error.rb', line 5

def error(x, status:200, type:nil, title:"An error occurred", message:"", args: [])
   x.res.status = status
   App[:app_error][type.to_sym][:get].call(x, title, message, *args)
end

#fatal(x, e) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'waxx/error.rb', line 10

def fatal(x, e)
  App::AppLog.log(x, cat: "Error", name:"#{x.req.uri}", value: "#{e}\n#{e.backtrace}")
  x.res.status = 503
  er = [
    "ERROR:\n#{e}\n#{e.backtrace.join("\n")}",
    "USR:\n\n#{x.usr.map{|n,v| "#{n}: #{v}"}.join("\n")}",
    "GET:\n#{x.req.get.map{|n,v| "#{n}: #{v}"}.join("\n")}",
    "POST:\n#{req.post.map{|n,v| "#{n}: #{v}"}.join("\n")}",
    "ENV:\n\n#{x.req.env.map{|n,v| "#{n}: #{v}"}.join("\n")}"
  ].join("\n\n")

  if Waxx['debug']['on_screen']
    x << "<pre>#{er}</pre>"
  else
    get_const(App, x.ext).get(x,
      title: "System Error",
      content: "<h4><span class='glyphicon glyphicon-thumbs-down'></span> Sorry! Something went wrong on our end.</h4>
        <h4><span class='glyphicon glyphicon-thumbs-up'></span> The tech support team has been notified.</h4>
        <p>We will contact you if we need addition information. </p>
        <p>Sorry for the inconvenience.</p>"
    )
  end
  if Waxx['debug']['send_email'] and Waxx['debug']['email']
    to_email = Waxx['debug']['email']
    from_email = Waxx['site']['support_email']
    subject = "[Bug] #{App['site']['name']} #{x.meth}:#{x.uri}"
    body = er
    begin
      # Send email via DB.email table
      App::Email.post(x,{
        to_email: to_email,
        from_email: from_email,
        subject: subject,
        body: body
      })
    rescue => e2
      begin
        # Only send email
        Mail.deliver do
          from     from_email
          to       to_email
          subject  subject
          body     body
        end
      rescue => e3
         puts "FATAL ERROR: Could not send bug report email: #{e2}\n#{e2.backtrace} AND #{e3}\n#{e3.backtrace}"
      end
    end
  end
end