mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Refactor and simplify query tool connection error handling code. Fixes #3235
This commit is contained in:
committed by
Dave Page
parent
be055ce57d
commit
a705fb46a8
@@ -11,7 +11,7 @@ import gettext from '../gettext';
|
||||
import $ from 'jquery';
|
||||
import url_for from '../url_for';
|
||||
import axios from 'axios';
|
||||
import * as transaction from './is_new_transaction_required';
|
||||
import * as httpErrorHandler from './query_tool_http_error_handler';
|
||||
|
||||
class LoadingScreen {
|
||||
constructor(sqlEditor) {
|
||||
@@ -152,8 +152,8 @@ class ExecuteQuery {
|
||||
|
||||
const errorData = error.response.data;
|
||||
|
||||
if (self.userManagement.is_pga_login_required(errorData)) {
|
||||
return self.userManagement.pga_login();
|
||||
if (self.userManagement.isPgaLoginRequired(errorData)) {
|
||||
return self.userManagement.pgaLogin();
|
||||
}
|
||||
|
||||
let msg = ExecuteQuery.extractErrorMessage(errorData);
|
||||
@@ -198,18 +198,18 @@ class ExecuteQuery {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.userManagement.is_pga_login_required(httpMessage.response)) {
|
||||
this.sqlServerObject.save_state('execute', [this.explainPlan]);
|
||||
this.userManagement.pga_login();
|
||||
if (this.userManagement.isPgaLoginRequired(httpMessage.response)) {
|
||||
this.sqlServerObject.saveState('execute', [this.explainPlan]);
|
||||
this.userManagement.pgaLogin();
|
||||
}
|
||||
|
||||
if (transaction.is_new_transaction_required(httpMessage.response)) {
|
||||
this.sqlServerObject.save_state('execute', [this.explainPlan]);
|
||||
this.sqlServerObject.init_transaction();
|
||||
if (httpErrorHandler.httpResponseRequiresNewTransaction(httpMessage.response)) {
|
||||
this.sqlServerObject.saveState('execute', [this.explainPlan]);
|
||||
this.sqlServerObject.initTransaction();
|
||||
}
|
||||
|
||||
if (this.wasDatabaseConnectionLost(httpMessage)) {
|
||||
this.sqlServerObject.save_state('execute', [this.explainPlan]);
|
||||
this.sqlServerObject.saveState('execute', [this.explainPlan]);
|
||||
this.sqlServerObject.handle_connection_lost(false, httpMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
export function is_new_transaction_required(xhr) {
|
||||
/* If responseJSON is undefined then it could be object of
|
||||
* axios(Promise HTTP) response, so we should check accordingly.
|
||||
*/
|
||||
if (xhr.responseJSON === undefined && xhr.data !== undefined) {
|
||||
return xhr.status === 404 && xhr.data &&
|
||||
xhr.data.info &&
|
||||
xhr.data.info === 'DATAGRID_TRANSACTION_REQUIRED';
|
||||
}
|
||||
|
||||
return xhr.status === 404 && xhr.responseJSON &&
|
||||
xhr.responseJSON.info &&
|
||||
xhr.responseJSON.info === 'DATAGRID_TRANSACTION_REQUIRED';
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
import gettext from 'sources/gettext';
|
||||
|
||||
export function httpResponseRequiresNewTransaction(xhr) {
|
||||
/* If responseJSON is undefined then it could be object of
|
||||
* axios(Promise HTTP) response, so we should check accordingly.
|
||||
*/
|
||||
if (xhr.responseJSON === undefined && xhr.data !== undefined) {
|
||||
return xhr.status === 404 && xhr.data &&
|
||||
xhr.data.info &&
|
||||
xhr.data.info === 'DATAGRID_TRANSACTION_REQUIRED';
|
||||
}
|
||||
|
||||
return xhr.status === 404 && xhr.responseJSON &&
|
||||
xhr.responseJSON.info &&
|
||||
xhr.responseJSON.info === 'DATAGRID_TRANSACTION_REQUIRED';
|
||||
}
|
||||
|
||||
// Allow us to redirect to login dialog and if required then re-initiate the transaction
|
||||
export function handleLoginRequiredAndTransactionRequired(
|
||||
pgAdmin, handler, exception, stateToSave, stateParameters, checkTransaction
|
||||
) {
|
||||
stateParameters = stateParameters && stateParameters.length > 0 ? stateParameters : [];
|
||||
if (pgAdmin.Browser.UserManagement.isPgaLoginRequired(exception)) {
|
||||
if (stateToSave) {
|
||||
handler.saveState(stateToSave, stateParameters);
|
||||
}
|
||||
return pgAdmin.Browser.UserManagement.pgaLogin();
|
||||
}
|
||||
|
||||
if(checkTransaction && httpResponseRequiresNewTransaction(exception)) {
|
||||
if (stateToSave) {
|
||||
handler.saveState(stateToSave, stateParameters);
|
||||
}
|
||||
return handler.initTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
// Allow us to handle the AJAX error from Query tool
|
||||
export function handleQueryToolAjaxError(
|
||||
pgAdmin, handler, exception, stateToSave, stateParameters, checkTransaction
|
||||
) {
|
||||
if (exception.readyState === 0) {
|
||||
return gettext('Not connected to the server or the connection to the server has been closed.');
|
||||
}
|
||||
|
||||
handleLoginRequiredAndTransactionRequired(
|
||||
pgAdmin, handler, exception, stateToSave, stateParameters, checkTransaction
|
||||
);
|
||||
|
||||
let msg = exception.responseText;
|
||||
if (exception.responseJSON !== undefined) {
|
||||
if(exception.responseJSON.errormsg !== undefined) {
|
||||
msg = exception.responseJSON.errormsg;
|
||||
}
|
||||
|
||||
if(exception.status === 503 && exception.responseJSON.info !== undefined &&
|
||||
exception.responseJSON.info == 'CONNECTION_LOST') {
|
||||
setTimeout(function() {
|
||||
if (stateToSave) {
|
||||
handler.saveState(stateToSave, stateParameters);
|
||||
}
|
||||
handler.handle_connection_lost(false, exception);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
Reference in New Issue
Block a user