(error, args)
| 435 | } |
| 436 | |
| 437 | export function pgHandleItemError(error, args) { |
| 438 | let pgBrowser = window.pgAdmin.Browser; |
| 439 | |
| 440 | if (!error || !pgBrowser) { |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | if(error.response.headers['content-type'] == 'application/json') { |
| 445 | let jsonResp = error.response.data; |
| 446 | if ( |
| 447 | jsonResp && ( |
| 448 | error.response.status == 503 ? ( |
| 449 | jsonResp.info == 'CONNECTION_LOST' && |
| 450 | 'server' in args.info && jsonResp.data.sid >= 0 && |
| 451 | jsonResp.data.sid == args.info.server._id |
| 452 | ) : ( |
| 453 | error.response.status == 428 && |
| 454 | jsonResp.errormsg && |
| 455 | jsonResp.errormsg == gettext('Connection to the server has been lost.') |
| 456 | ) |
| 457 | ) |
| 458 | ) { |
| 459 | if ( |
| 460 | args.preHandleConnectionLost && |
| 461 | typeof(args.preHandleConnectionLost) == 'function' |
| 462 | ) { |
| 463 | args.preHandleConnectionLost.apply(this, arguments); |
| 464 | } |
| 465 | |
| 466 | // Check the status of the maintenance server connection. |
| 467 | let server = pgBrowser.Nodes['server'], |
| 468 | ctx = { |
| 469 | resp: jsonResp, |
| 470 | error: error, |
| 471 | args: args, |
| 472 | }, |
| 473 | reconnectServer = function() { |
| 474 | let ctx_local = this, |
| 475 | onServerConnect = function(_sid, _i, _d) { |
| 476 | // Yay - server is reconnected. |
| 477 | if (this.args.info.server._id == _sid) { |
| 478 | pgBrowser.Events.off( |
| 479 | 'pgadmin:server:connected', onServerConnect |
| 480 | ); |
| 481 | pgBrowser.Events.off( |
| 482 | 'pgadmin:server:connect:cancelled', onConnectCancel |
| 483 | ); |
| 484 | |
| 485 | // Do we need to connect the disconnected server now? |
| 486 | if ( |
| 487 | this.resp.data.database && |
| 488 | this.resp.data.database != _d.db |
| 489 | ) { |
| 490 | // Server is connected now, we will need to inform the |
| 491 | // database to connect it now. |
| 492 | pgBrowser.Events.trigger( |
| 493 | 'pgadmin:database:connection:lost', this.args.item, |
| 494 | this.resp, true |
nothing calls this directly
no test coverage detected