[Graph] Switch to core http (#49487)
This commit is contained in:
parent
601800c9aa
commit
6cd624f25a
|
@ -11,9 +11,7 @@ import React from 'react';
|
|||
import { Provider } from 'react-redux';
|
||||
import { isColorDark, hexToRgb } from '@elastic/eui';
|
||||
|
||||
import { KibanaParsedUrl } from 'ui/url/kibana_parsed_url';
|
||||
import { showSaveModal } from 'ui/saved_objects/show_saved_object_save_modal';
|
||||
import { formatAngularHttpError } from 'ui/notify/lib';
|
||||
import { addAppRedirectMessageToUrl } from 'ui/notify';
|
||||
|
||||
import appTemplate from './angular/templates/index.html';
|
||||
|
@ -39,6 +37,7 @@ import {
|
|||
datasourceSelector,
|
||||
hasFieldsSelector
|
||||
} from './state_management';
|
||||
import { formatHttpError } from './helpers/format_http_error';
|
||||
|
||||
export function initGraphApp(angularModule, deps) {
|
||||
const {
|
||||
|
@ -56,7 +55,6 @@ export function initGraphApp(angularModule, deps) {
|
|||
savedObjectRegistry,
|
||||
capabilities,
|
||||
coreStart,
|
||||
$http,
|
||||
Storage,
|
||||
canEditDrillDownUrls,
|
||||
graphSavePolicy,
|
||||
|
@ -208,31 +206,35 @@ export function initGraphApp(angularModule, deps) {
|
|||
|
||||
async function handleHttpError(error) {
|
||||
checkLicense(kbnBaseUrl);
|
||||
toastNotifications.addDanger(formatAngularHttpError(error));
|
||||
toastNotifications.addDanger(formatHttpError(error));
|
||||
}
|
||||
|
||||
// Replacement function for graphClientWorkspace's comms so
|
||||
// that it works with Kibana.
|
||||
function callNodeProxy(indexName, query, responseHandler) {
|
||||
const request = {
|
||||
index: indexName,
|
||||
query: query
|
||||
body: JSON.stringify({
|
||||
index: indexName,
|
||||
query: query
|
||||
})
|
||||
};
|
||||
$scope.loading = true;
|
||||
return $http.post('../api/graph/graphExplore', request)
|
||||
.then(function (resp) {
|
||||
if (resp.data.resp.timed_out) {
|
||||
return coreStart.http.post('../api/graph/graphExplore', request)
|
||||
.then(function (data) {
|
||||
const response = data.resp;
|
||||
if (response.timed_out) {
|
||||
toastNotifications.addWarning(
|
||||
i18n.translate('xpack.graph.exploreGraph.timedOutWarningText', {
|
||||
defaultMessage: 'Exploration timed out',
|
||||
})
|
||||
);
|
||||
}
|
||||
responseHandler(resp.data.resp);
|
||||
responseHandler(response);
|
||||
})
|
||||
.catch(handleHttpError)
|
||||
.finally(() => {
|
||||
$scope.loading = false;
|
||||
$scope.$digest();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -240,17 +242,21 @@ export function initGraphApp(angularModule, deps) {
|
|||
//Helper function for the graphClientWorkspace to perform a query
|
||||
const callSearchNodeProxy = function (indexName, query, responseHandler) {
|
||||
const request = {
|
||||
index: indexName,
|
||||
body: query
|
||||
body: JSON.stringify({
|
||||
index: indexName,
|
||||
body: query
|
||||
})
|
||||
};
|
||||
$scope.loading = true;
|
||||
$http.post('../api/graph/searchProxy', request)
|
||||
.then(function (resp) {
|
||||
responseHandler(resp.data.resp);
|
||||
coreStart.http.post('../api/graph/searchProxy', request)
|
||||
.then(function (data) {
|
||||
const response = data.resp;
|
||||
responseHandler(response);
|
||||
})
|
||||
.catch(handleHttpError)
|
||||
.finally(() => {
|
||||
$scope.loading = false;
|
||||
$scope.$digest();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { IHttpFetchError } from 'kibana/public';
|
||||
|
||||
export function formatHttpError(error: IHttpFetchError) {
|
||||
if (!error.response) {
|
||||
return i18n.translate('xpack.graph.fatalError.unavailableServerErrorMessage', {
|
||||
defaultMessage:
|
||||
'An HTTP request has failed to connect. ' +
|
||||
'Please check if the Kibana server is running and that your browser has a working connection, ' +
|
||||
'or contact your system administrator.',
|
||||
});
|
||||
}
|
||||
return i18n.translate('xpack.graph.fatalError.errorStatusMessage', {
|
||||
defaultMessage: 'Error {errStatus} {errStatusText}: {errMessage}',
|
||||
values: {
|
||||
errStatus: error.body.status,
|
||||
errStatusText: error.body.statusText,
|
||||
errMessage: error.body.message,
|
||||
},
|
||||
});
|
||||
}
|
|
@ -36,7 +36,6 @@ async function getAngularInjectedDependencies(): Promise<LegacyAngularInjectedDe
|
|||
const Private = injector.get<IPrivate>('Private');
|
||||
|
||||
return {
|
||||
$http: injector.get('$http'),
|
||||
savedObjectRegistry: Private(SavedObjectRegistryProvider),
|
||||
kbnBaseUrl: injector.get('kbnBaseUrl'),
|
||||
savedGraphWorkspaces: Private(SavedWorkspacesProvider),
|
||||
|
|
|
@ -63,10 +63,6 @@ export interface GraphDependencies extends LegacyAngularInjectedDependencies {
|
|||
* These dependencies have to be migrated to their NP counterparts.
|
||||
*/
|
||||
export interface LegacyAngularInjectedDependencies {
|
||||
/**
|
||||
* angular $http service
|
||||
*/
|
||||
$http: any;
|
||||
/**
|
||||
* Instance of SavedObjectRegistryProvider
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue