Esempio n. 1
0
def handle_exception(e):
	response = None
	http_status_code = getattr(e, "http_status_code", 500)
	return_as_message = False

	if frappe.get_request_header('Accept') and (frappe.local.is_ajax or 'application/json' in frappe.get_request_header('Accept')):
		# handle ajax responses first
		# if the request is ajax, send back the trace or error message
		response = frappe.utils.response.report_error(http_status_code)

	elif (http_status_code==500
		and (frappe.db and isinstance(e, frappe.db.InternalError))
		and (frappe.db and (frappe.db.is_deadlocked(e) or frappe.db.is_timedout(e)))):
			http_status_code = 508

	elif http_status_code==401:
		frappe.respond_as_web_page(_("Session Expired"),
			_("Your session has expired, please login again to continue."),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	elif http_status_code==403:
		frappe.respond_as_web_page(_("Not Permitted"),
			_("You do not have enough permissions to complete the action"),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	elif http_status_code==404:
		frappe.respond_as_web_page(_("Not Found"),
			_("The resource you are looking for is not available"),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	else:
		traceback = "<pre>"+frappe.get_traceback()+"</pre>"
		if frappe.local.flags.disable_traceback:
			traceback = ""

		frappe.respond_as_web_page("Server Error",
			traceback, http_status_code=http_status_code,
			indicator_color='red', width=640)
		return_as_message = True

	if e.__class__ == frappe.AuthenticationError:
		if hasattr(frappe.local, "login_manager"):
			frappe.local.login_manager.clear_cookies()

	if http_status_code >= 500:
		if not frappe.conf.developer_mode:
			for fn in frappe.get_hooks("exception_handlers"):
				frappe.get_attr(fn)()

		frappe.logger().error('Request Error', exc_info=True)
		make_error_snapshot(e)

	if return_as_message:
		response = frappe.website.render.render("message",
			http_status_code=http_status_code)

	return response
Esempio n. 2
0
def handle_exception(e):
	http_status_code = getattr(e, "http_status_code", 500)

	if (http_status_code==500
		and isinstance(e, MySQLdb.OperationalError)
		and e.args[0] in (1205, 1213)):
			# 1205 = lock wait timeout
			# 1213 = deadlock
			# code 409 represents conflict
			http_status_code = 508

	if frappe.local.is_ajax or 'application/json' in frappe.local.request.headers.get('Accept', ''):
		response = frappe.utils.response.report_error(http_status_code)
	else:
		traceback = "<pre>"+frappe.get_traceback()+"</pre>"
		if frappe.local.flags.disable_traceback:
			traceback = ""

		frappe.respond_as_web_page("Server Error",
			traceback,
			http_status_code=http_status_code)
		response = frappe.website.render.render("message", http_status_code=http_status_code)

	if e.__class__ == frappe.AuthenticationError:
		if hasattr(frappe.local, "login_manager"):
			frappe.local.login_manager.clear_cookies()

	if http_status_code >= 500:
		frappe.logger().error('Request Error', exc_info=True)
		make_error_snapshot(e)

	return response
Esempio n. 3
0
def handle_exception(e):
    http_status_code = getattr(e, "http_status_code", 500)

    if (http_status_code == 500 and isinstance(e, MySQLdb.OperationalError)
            and e.args[0] in (1205, 1213)):
        # 1205 = lock wait timeout
        # 1213 = deadlock
        # code 409 represents conflict
        http_status_code = 508

    if frappe.local.is_ajax or 'application/json' in frappe.local.request.headers.get(
            'Accept', ''):
        response = frappe.utils.response.report_error(http_status_code)
    else:
        traceback = "<pre>" + frappe.get_traceback() + "</pre>"
        if frappe.local.flags.disable_traceback:
            traceback = ""

        frappe.respond_as_web_page("Server Error",
                                   traceback,
                                   http_status_code=http_status_code)
        response = frappe.website.render.render(
            "message", http_status_code=http_status_code)

    if e.__class__ == frappe.AuthenticationError:
        if hasattr(frappe.local, "login_manager"):
            frappe.local.login_manager.clear_cookies()

    if http_status_code >= 500:
        logger.error('Request Error')
        make_error_snapshot(e)

    return response
Esempio n. 4
0
def _execute_actions(action_list, queue='default'):
	for action in action_list:
		try:
			if not action.execute_when or bool(evaluate_js(action.execute_when)):
				_execute_action(action, queue)
		except Exception as e:
			make_error_snapshot(e)
Esempio n. 5
0
def handle_exception(e):
	response = None
	http_status_code = getattr(e, "http_status_code", 500)
	return_as_message = False

	if frappe.local.is_ajax or 'application/json' in frappe.get_request_header('Accept'):
		# handle ajax responses first
		# if the request is ajax, send back the trace or error message
		response = frappe.utils.response.report_error(http_status_code)

	elif (http_status_code==500
		and isinstance(e, MySQLdb.OperationalError)
		and e.args[0] in (1205, 1213)):
			# 1205 = lock wait timeout
			# 1213 = deadlock
			# code 409 represents conflict
			http_status_code = 508

	elif http_status_code==401:
		frappe.respond_as_web_page(_("Session Expired"),
			_("Your session has expired, please login again to continue."),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	elif http_status_code==403:
		frappe.respond_as_web_page(_("Not Permitted"),
			_("You do not have enough permissions to complete the action"),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	elif http_status_code==404:
		frappe.respond_as_web_page(_("Not Found"),
			_("The resource you are looking for is not available"),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	else:
		traceback = "<pre>"+frappe.get_traceback()+"</pre>"
		if frappe.local.flags.disable_traceback:
			traceback = ""

		frappe.respond_as_web_page("Server Error",
			traceback, http_status_code=http_status_code,
			indicator_color='red', width=640)
		return_as_message = True

	if e.__class__ == frappe.AuthenticationError:
		if hasattr(frappe.local, "login_manager"):
			frappe.local.login_manager.clear_cookies()

	if http_status_code >= 500:
		frappe.logger().error('Request Error', exc_info=True)
		make_error_snapshot(e)

	if return_as_message:
		response = frappe.website.render.render("message",
			http_status_code=http_status_code)

	return response
Esempio n. 6
0
def handle_exception(e):
	response = None
	http_status_code = getattr(e, "http_status_code", 500)
	return_as_message = False

	if frappe.local.is_ajax or 'application/json' in frappe.local.request.headers.get('Accept', ''):
		# handle ajax responses first
		# if the request is ajax, send back the trace or error message
		response = frappe.utils.response.report_error(http_status_code)

	elif (http_status_code==500
		and isinstance(e, MySQLdb.OperationalError)
		and e.args[0] in (1205, 1213)):
			# 1205 = lock wait timeout
			# 1213 = deadlock
			# code 409 represents conflict
			http_status_code = 508

	elif http_status_code==401:
		frappe.respond_as_web_page(_("Session Expired"),
			_("Your session has expired, please login again to continue."),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	elif http_status_code==403:
		frappe.respond_as_web_page(_("Not Permitted"),
			_("You do not have enough permissions to complete the action"),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	elif http_status_code==404:
		frappe.respond_as_web_page(_("Not Found"),
			_("The resource you are looking for is not available"),
			http_status_code=http_status_code,  indicator_color='red')
		return_as_message = True

	else:
		traceback = "<pre>"+frappe.get_traceback()+"</pre>"
		if frappe.local.flags.disable_traceback:
			traceback = ""

		frappe.respond_as_web_page("Server Error",
			traceback, http_status_code=http_status_code,
			indicator_color='red')
		return_as_message = True

	if e.__class__ == frappe.AuthenticationError:
		if hasattr(frappe.local, "login_manager"):
			frappe.local.login_manager.clear_cookies()

	if http_status_code >= 500:
		frappe.logger().error('Request Error', exc_info=True)
		make_error_snapshot(e)

	if return_as_message:
		response = frappe.website.render.render("message",
			http_status_code=http_status_code)

	return response
Esempio n. 7
0
	def receive(self, test_mails=None):
		"""Called by scheduler to receive emails from this EMail account using POP3/IMAP."""
		if self.enable_incoming:
			if frappe.local.flags.in_test:
				incoming_mails = test_mails
			else:
				email_server = self.get_server(in_receive=True)
				if not email_server:
					return
				incoming_mails = email_server.get_messages()

			exceptions = []

			for msg in incoming_mails:
				try:

					communication = self.insert_communication(msg)
					#self.notify_update()

				except SentEmailInInbox,e:
					frappe.db.rollback()
					make_error_snapshot(e)
					if self.use_imap:
						self.handle_bad_emails(email_server, msg[1], msg[0],"sent email in inbox")


				except Exception, e:
					frappe.db.rollback()
					make_error_snapshot(e)
					if self.use_imap:
						self.handle_bad_emails(email_server, msg[1], msg[0],frappe.get_traceback())
					exceptions.append(frappe.get_traceback())

				else:
					frappe.db.commit()
					attachments = [d.file_name for d in communication._attachments]

					if communication.message_id and not communication.timeline_hide:
						first = frappe.db.get_value("Communication", {"message_id": communication.message_id},["name"],as_dict=1)
						if first:
							if first.name != communication.name:
								communication.db_set("timeline_hide",first.name,update_modified=False)
					
					if self.no_remaining == '0' and not frappe.local.flags.in_test:
						if communication.reference_doctype :
							if not communication.timeline_hide and not communication.unread_notification_sent:
								communication.notify(attachments=attachments, fetched_from_email_account=True)
    def __init__(self, connector):
        self.connector = connector
        settings = frappe.get_doc("Mautic Settings", None)

        self.base_url = settings.base_url
        self.token = {
            'refresh_token':
            settings.get_password(fieldname='refresh_token',
                                  raise_exception=False),
            'access_token':
            settings.get_password(fieldname='session_token',
                                  raise_exception=False),
            'token_type':
            'Bearer',
            'expires_in':
            '-30'
        }
        self.client_id = settings.client_id
        self.client_secret = settings.get_password(fieldname='client_secret',
                                                   raise_exception=False)

        self.name_field = 'id'

        try:
            self.mautic_connect = MauticOauth2Client(
                base_url=self.base_url,
                client_id=self.client_id,
                client_secret=self.client_secret,
                token=self.token,
                token_updater=refresh_token)
        except Exception as e:
            make_error_snapshot(e)

        if not hasattr(self.mautic_connect, 'session'):
            frappe.throw(
                _("Your Mautic Connection Token has expired. Please renew it.")
            )
            frappe.logger().error(' Mautic Connection Token has expired')
Esempio n. 9
0
                traceback = ""

            frappe.respond_as_web_page("Server Error",
                                       traceback,
                                       http_status_code=http_status_code)
            response = frappe.website.render.render(
                "message", http_status_code=http_status_code)

        if e.__class__ == frappe.AuthenticationError:
            if hasattr(frappe.local, "login_manager"):
                frappe.local.login_manager.clear_cookies()

        if http_status_code == 500:
            logger.error('Request Error')

        make_error_snapshot(e)

    else:
        if (frappe.local.request.method in ("POST", "PUT")
                or frappe.local.flags.commit) and frappe.db:
            if frappe.db.transaction_writes:
                frappe.db.commit()
                rollback = False

        # update session
        if getattr(frappe.local, "session_obj", None):
            updated_in_db = frappe.local.session_obj.update()
            if updated_in_db:
                frappe.db.commit()

        # publish realtime
Esempio n. 10
0
def handle_exception(e):
    response = None
    http_status_code = getattr(e, "http_status_code", 500)
    return_as_message = False
    accept_header = frappe.get_request_header("Accept") or ""
    respond_as_json = (
        frappe.get_request_header('Accept') and
        (frappe.local.is_ajax or 'application/json' in accept_header)
        or (frappe.local.request.path.startswith("/api/")
            and not accept_header.startswith("text")))

    if frappe.conf.get('developer_mode'):
        # don't fail silently
        print(frappe.get_traceback())

    if respond_as_json:
        # handle ajax responses first
        # if the request is ajax, send back the trace or error message
        response = frappe.utils.response.report_error(http_status_code)

    elif (http_status_code == 500
          and (frappe.db and isinstance(e, frappe.db.InternalError))
          and (frappe.db and
               (frappe.db.is_deadlocked(e) or frappe.db.is_timedout(e)))):
        http_status_code = 508

    elif http_status_code == 401:
        frappe.respond_as_web_page(
            _("Session Expired"),
            _("Your session has expired, please login again to continue."),
            http_status_code=http_status_code,
            indicator_color='red')
        return_as_message = True

    elif http_status_code == 403:
        frappe.respond_as_web_page(
            _("Not Permitted"),
            _("You do not have enough permissions to complete the action"),
            http_status_code=http_status_code,
            indicator_color='red')
        return_as_message = True

    elif http_status_code == 404:
        frappe.respond_as_web_page(
            _("Not Found"),
            _("The resource you are looking for is not available"),
            http_status_code=http_status_code,
            indicator_color='red')
        return_as_message = True

    elif http_status_code == 429:
        response = frappe.rate_limiter.respond()

    else:
        traceback = "<pre>" + sanitize_html(frappe.get_traceback()) + "</pre>"
        if frappe.local.flags.disable_traceback:
            traceback = ""

        frappe.respond_as_web_page("Server Error",
                                   traceback,
                                   http_status_code=http_status_code,
                                   indicator_color='red',
                                   width=640)
        return_as_message = True

    if e.__class__ == frappe.AuthenticationError:
        if hasattr(frappe.local, "login_manager"):
            frappe.local.login_manager.clear_cookies()

    if http_status_code >= 500:
        try:
            from sentry.utils import capture_exception
            capture_exception()
        except:
            pass

        frappe.logger().error('Request Error', exc_info=True)
        make_error_snapshot(e)

    if return_as_message:
        response = frappe.website.render.render(
            "message", http_status_code=http_status_code)

    return response
Esempio n. 11
0
			if frappe.local.flags.disable_traceback:
				traceback = ""

			frappe.respond_as_web_page("Server Error",
				traceback,
				http_status_code=http_status_code)
			response = frappe.website.render.render("message", http_status_code=http_status_code)

		if e.__class__ == frappe.AuthenticationError:
			if hasattr(frappe.local, "login_manager"):
				frappe.local.login_manager.clear_cookies()

		if http_status_code==500:
			logger.error('Request Error')

		make_error_snapshot(e)

	else:
		if (frappe.local.request.method in ("POST", "PUT") or frappe.local.flags.commit) and frappe.db:
			if frappe.db.transaction_writes:
				frappe.db.commit()
				rollback = False

		# update session
		if getattr(frappe.local, "session_obj", None):
			updated_in_db = frappe.local.session_obj.update()
			if updated_in_db:
				frappe.db.commit()

		# publish realtime
		for args in frappe.local.realtime_log: