[Graph] Switch to core http (#49487)

This commit is contained in:
Joe Reuter 2019-11-04 12:57:21 +01:00 committed by GitHub
parent 601800c9aa
commit 6cd624f25a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 20 deletions

View file

@ -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();
});
};

View file

@ -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,
},
});
}

View file

@ -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),

View file

@ -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
*/