Skip to content

Commit

Permalink
handle_mailin: Notify the admin when there's a 500 server error.
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkp committed Nov 3, 2009
1 parent d5a601f commit eccfb6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
32 changes: 24 additions & 8 deletions fixcity/bmabr/management/commands/handle_mailin.py
Expand Up @@ -286,10 +286,15 @@ def new_rack(self, title, address, spam):
print "TD: server responded with:\n%s" % content

if response.status >= 500:
err_msg = ("Thanks for trying to suggest a rack.\n"
"We are unfortunately experiencing some difficulties\n"
"at the moment -- please try again later!\n")
self.bounce(error_subject, err_msg)
err_msg = (
"Thanks for trying to suggest a rack.\n"
"Unfortunately there was a server error and your rack could\n"
"not be processed. The fixcity staff are being notified and\n"
"will fix the problem as soon as possible.\n"
)
admin_body = content
self.bounce(error_subject, err_msg, notify_admin='500 Server error',
notify_admin_body=content)
return

result = json.loads(content)
Expand Down Expand Up @@ -627,7 +632,7 @@ def attachments(self, message_parts):
# Check if the attachment size is allowed
#
if (max_size != -1) and (file_size > max_size):
status = '%s\nFile %s is larger then allowed attachment size (%d > %d)\n\n' \
status = '%s\nFile %s is larger than allowed attachment size (%d > %d)\n\n' \
%(status, original, file_size, max_size)
continue

Expand All @@ -640,18 +645,29 @@ def attachments(self, message_parts):
return results


def bounce(self, subject, body, notify_admin):
def bounce(self, subject, body, notify_admin='', notify_admin_body=''):
"""Bounce a message to the sender, with additional subject
and body for explanation.
If the notify_admin string is non-empty, the site admin will
be notified, with that string appended to the subject.
If notify_admin_body is non-empty, it will be added to the body
sent to the admin.
"""
if self.DEBUG:
print "TD: Bouncing message to %s" % self.email_addr
body += '\n\n------------ original message follows ---------\n\n'
# TO DO: use attachments rather than inline.
body += self.msg.as_string()
if notify_admin:
admin_subject = 'FixCity handle_mailin bounce! %s' % notify_admin
admin_body = 'Bouncing to: %s\n' % self.msg['to']
admin_body += 'Bounce subject: %r\n' % subject
admin_body += 'Time: %s\n' % datetime.now().isoformat(' ')
admin_body += '--- Bounce message follows --------\n'
admin_body += body
admin_body += 'Not attaching original body, check the log file.'
if notify_admin_body:
admin_body += 'Additional info:\n'
admin_body += notify_admin_body
self.notify_admin(admin_subject, admin_body)
return self.reply(subject, body)

Expand Down
1 change: 1 addition & 0 deletions fixcity/bmabr/views.py
Expand Up @@ -341,6 +341,7 @@ def rack_index(request):


def newrack_json(request):
raise ValueError("Bwahahaha")
if request.method != 'POST':
return HttpResponseNotAllowed(['POST'])
# I would think there'd be a more useful way to get Django to
Expand Down

0 comments on commit eccfb6c

Please sign in to comment.