From 74c21db40fb8a0a088959df880e14abaa268aba4 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 27 Feb 2015 13:38:29 +0530 Subject: [PATCH] Better message for lock wait timeout and deadlock --- frappe/app.py | 9 +++++++++ frappe/public/js/frappe/request.js | 3 +++ 2 files changed, 12 insertions(+) diff --git a/frappe/app.py b/frappe/app.py index 822c061b67..76018e391e 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import sys, os import json import logging +import MySQLdb from werkzeug.wrappers import Request, Response from werkzeug.local import LocalManager @@ -70,6 +71,14 @@ def application(request): except 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 = 409 + if frappe.local.is_ajax: response = frappe.utils.response.report_error(http_status_code) else: diff --git a/frappe/public/js/frappe/request.js b/frappe/public/js/frappe/request.js index 1618d213e5..50145a155d 100644 --- a/frappe/public/js/frappe/request.js +++ b/frappe/public/js/frappe/request.js @@ -66,6 +66,9 @@ frappe.request.call = function(opts) { msgprint(__("Not permitted")); }, + 409: function(xhr) { + msgprint(__("Another transaction is blocking this one. Please try again in a few seconds.")); + }, 417: function(data, xhr) { if(typeof data === "string") data = JSON.parse(data); opts.error_callback && opts.error_callback(data, xhr.responseText);