2016-08-29 01:22:50 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2018-01-05 04:42:49 -06:00
|
|
|
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
2016-08-29 01:22:50 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
from werkzeug.exceptions import HTTPException
|
|
|
|
from werkzeug.http import HTTP_STATUS_CODES
|
|
|
|
from flask_babel import gettext as _
|
|
|
|
from flask import request
|
|
|
|
|
|
|
|
from pgadmin.utils.ajax import service_unavailable
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectionLost(HTTPException):
|
|
|
|
"""
|
|
|
|
Exception
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, _server_id, _database_name, _conn_id):
|
|
|
|
self.sid = _server_id
|
|
|
|
self.db = _database_name
|
|
|
|
self.conn_id = _conn_id
|
|
|
|
HTTPException.__init__(self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
return HTTP_STATUS_CODES.get(505, 'Service Unavailable')
|
|
|
|
|
|
|
|
def get_response(self, environ=None):
|
|
|
|
return service_unavailable(
|
2017-11-01 10:18:07 -05:00
|
|
|
_("Connection to the server has been lost."),
|
2016-08-29 01:22:50 -05:00
|
|
|
info="CONNECTION_LOST",
|
|
|
|
data={
|
|
|
|
'sid': self.sid,
|
|
|
|
'database': self.db,
|
|
|
|
'conn_id': self.conn_id
|
|
|
|
}
|
|
|
|
)
|
2017-07-07 01:25:55 -05:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Connection (id #{2}) lost for the server (#{0}) on " \
|
|
|
|
"database ({1})".format(self.sid, self.db, self.conn_id)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "Connection (id #{2}) lost for the server (#{0}) on " \
|
|
|
|
"database ({1})".format(self.sid, self.db, self.conn_id)
|