コード例 #1
0
ファイル: Worker.py プロジェクト: Stamped/Stamped
def _warningEmail(subject):
    if libs.ec2_utils.is_ec2():
        try:
            email = {}
            email['from'] = 'Stamped <*****@*****.**>'
            email['to'] = '*****@*****.**'
            email['subject'] = subject
            email['body'] = logs.getHtmlFormattedLog()
            utils.sendEmail(email, format='html')
        except Exception as e:
            logs.warning('UNABLE TO SEND EMAIL: %s' % (e,))
コード例 #2
0
ファイル: helpers.py プロジェクト: Stamped/Stamped
def handleStampedExceptions(e, handlers=None):
    if isinstance(e, StampedHTTPError):
        exceptions =  [(StampedHTTPError, e.code, e.kind, e.msg)]
    elif handlers is not None:
        exceptions = handlers + defaultExceptions
    else:
        exceptions = defaultExceptions

    for (exception, code, kind, msg) in exceptions:
        if isinstance(e, exception):
            logs.warning("%s Error (%s): %s" % (code, kind, msg))
            logs.warning(utils.getFormattedException())
            logs.error(code)

            kind = kind
            if kind is None:
                kind = 'stamped_error'

            message = msg
            if message is None and e.msg is not None:
                message = e.msg

            error = {}
            error['error'] = kind
            if message is not None:
                error['message'] = unicode(message)

            return transformOutput(error, status=code)
    else:
        error = {
            'error' :   'stamped_error',
            'message' : "An error occurred. Please try again later.",
        }
        logs.warning("500 Error: %s" % e)
        logs.warning(utils.getFormattedException())
        logs.error(500)

        # Email dev if a 500 occurs
        if libs.ec2_utils.is_ec2():
            try:
                email = {}
                email['from'] = 'Stamped <*****@*****.**>'
                email['to'] = '*****@*****.**'
                email['subject'] = '%s - 500 Error - %s' % (stampedAPI.node_name, datetime.utcnow().isoformat())
                email['body'] = logs.getHtmlFormattedLog()
                utils.sendEmail(email, format='html')
            except Exception as e:
                logs.warning('UNABLE TO SEND EMAIL: %s')

        return transformOutput(error, status=500)