aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2020-09-19 16:01:49 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2020-09-19 16:01:49 +0530
commit92b2da20a115b978f9789e6e0a353d44ddcabe62 (patch)
treec7cc1f2ef71a540d89fb64272648d99856b346fa
parentd102cf38a122ed976e684db943b450512c761618 (diff)
added failed to connect to db error
-rw-r--r--app/misc.ini1
-rw-r--r--app/views.py28
2 files changed, 20 insertions, 9 deletions
diff --git a/app/misc.ini b/app/misc.ini
index cdf439c..be76896 100644
--- a/app/misc.ini
+++ b/app/misc.ini
@@ -7,6 +7,7 @@ OD03 = Failed to write the converted PDBQT file
PL02 = Failed to import PLIP, please ensure that you have correctly installed PLIP
PL01 = Failed to fetch the PDB, please check the PDB Code
+DB00 = Failed to connect to the database.
DB01 = This Job ID does not exist 😠. If you think this is an error, please contact us.
CW01 = Looks like an invalid PDB ID
diff --git a/app/views.py b/app/views.py
index 7fe1daa..1f02162 100644
--- a/app/views.py
+++ b/app/views.py
@@ -14,6 +14,9 @@ from datetime import datetime,date
import json
import subprocess
+import mysql.connector as con
+from mysql.connector.errors import InterfaceError
+
import requests
import logging
@@ -123,9 +126,12 @@ def status():
if request.method == 'POST':
if taskStatusForm.validate_on_submit():
jobID = taskStatusForm.jobID.data
- import mysql.connector as con
- mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
- mycursor = mycon.cursor()
+
+ try:
+ mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
+ mycursor = mycon.cursor()
+ except InterfaceError:
+ return render_template('error.html',code="DB00",description=errors['DB00'])
sqlQuery = 'select id, protein_name, ligand_name, date, description, done, pdb from curieweb where id="%s"' % (jobID)
mycursor.execute(sqlQuery)
records = mycursor.fetchall()
@@ -286,9 +292,11 @@ def dock_manual():
sx,sy,sz = str(form.size_x.data), str(form.size_y.data), str(form.size_z.data)
email = form.email.data
- import mysql.connector as con
- mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
- mycursor = mycon.cursor()
+ try:
+ mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
+ mycursor = mycon.cursor()
+ except InterfaceError:
+ return render_template("error.html",code="DB00",description=errors['DB00'])
import tempfile
with tempfile.TemporaryDirectory() as directory:
@@ -334,9 +342,11 @@ def dock_automatic():
if len(pdb) != 4:
return render_template("error.html",code="CW01",description=errors['CW01'])
- import mysql.connector as con
- mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
- mycursor = mycon.cursor()
+ try:
+ mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
+ mycursor = mycon.cursor()
+ except InterfaceError:
+ return render_template('error.html',code="DB00",description=errors['DB00'])
sqlQuery = "insert into curieweb (id, email, pdb, ligand_smile, ligand_name, date, description) values (%s,%s,%s,%s,%s,CURDATE(),%s) "
jobID = gen_word(16, 1, 1)