mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Security Solution] update generic policy response error (#143805)
This commit is contained in:
parent
12660923f1
commit
13bb47adf6
3 changed files with 62 additions and 9 deletions
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { FleetServerAgentComponentUnit } from '@kbn/fleet-plugin/common/types';
|
||||
|
||||
import { PackageActionFormatter, titles, descriptions } from './package_action_formatter';
|
||||
import { ENDPOINT_ERROR_CODES } from '../../../../common/endpoint/constants';
|
||||
|
||||
describe('PackageActionFormatter', () => {
|
||||
it('correctly formats es connection error', () => {
|
||||
const unit: FleetServerAgentComponentUnit = {
|
||||
id: 'test-id',
|
||||
type: 'input',
|
||||
status: 'failed',
|
||||
message: 'test message',
|
||||
payload: {
|
||||
error: {
|
||||
code: ENDPOINT_ERROR_CODES.ES_CONNECTION_ERROR,
|
||||
message: 'an error message',
|
||||
},
|
||||
},
|
||||
};
|
||||
const docLinks = { es_connection: 'somedoclink' };
|
||||
const formatter = new PackageActionFormatter(unit, docLinks);
|
||||
expect(formatter.key).toBe('es_connection');
|
||||
expect(formatter.title).toBe(titles.get('es_connection'));
|
||||
expect(formatter.description).toBe(descriptions.get('es_connection'));
|
||||
expect(formatter.linkUrl).toBe(docLinks.es_connection);
|
||||
});
|
||||
|
||||
it('correct formats generic error', () => {
|
||||
const unit: FleetServerAgentComponentUnit = {
|
||||
id: 'test-id',
|
||||
type: 'input',
|
||||
status: 'failed',
|
||||
message: 'test message',
|
||||
};
|
||||
const docLinks = { es_connection: 'somedoclink' };
|
||||
const formatter = new PackageActionFormatter(unit, docLinks);
|
||||
expect(formatter.key).toBe('policy_failure');
|
||||
expect(formatter.title).toBe(titles.get('policy_failure'));
|
||||
expect(formatter.description).toBe(descriptions.get('policy_failure'));
|
||||
});
|
||||
});
|
|
@ -7,6 +7,10 @@
|
|||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import type { DocLinks } from '@kbn/doc-links';
|
||||
import type {
|
||||
FleetServerAgentComponentUnit,
|
||||
FleetServerAgentComponentStatus,
|
||||
} from '@kbn/fleet-plugin/common/types';
|
||||
|
||||
import { ENDPOINT_ERROR_CODES } from '../../../../common/endpoint/constants';
|
||||
|
||||
|
@ -78,13 +82,12 @@ export class PackageActionFormatter {
|
|||
public linkText?: string;
|
||||
|
||||
constructor(
|
||||
code: number,
|
||||
message: string,
|
||||
unit: FleetServerAgentComponentUnit,
|
||||
private docLinks: DocLinks['securitySolution']['packageActionTroubleshooting']
|
||||
) {
|
||||
this.key = this.getKeyFromErrorCode(code);
|
||||
this.key = this.getKeyFromErrorCode(unit.payload?.error?.code, unit.status);
|
||||
this.title = titles.get(this.key) ?? this.key;
|
||||
this.description = descriptions.get(this.key) || message;
|
||||
this.description = descriptions.get(this.key) || unit.payload?.error?.message;
|
||||
this.linkText = linkTexts.get(this.key);
|
||||
}
|
||||
|
||||
|
@ -94,10 +97,13 @@ export class PackageActionFormatter {
|
|||
];
|
||||
}
|
||||
|
||||
private getKeyFromErrorCode(code: number): PackageActions {
|
||||
private getKeyFromErrorCode(
|
||||
code: number,
|
||||
status: FleetServerAgentComponentStatus
|
||||
): PackageActions {
|
||||
if (code === ENDPOINT_ERROR_CODES.ES_CONNECTION_ERROR) {
|
||||
return 'es_connection';
|
||||
} else if (code === 124) {
|
||||
} else if (status === 'failed') {
|
||||
return 'policy_failure';
|
||||
} else {
|
||||
throw new Error(`Invalid error code ${code}`);
|
||||
|
|
|
@ -23,11 +23,10 @@ export const EndpointGenericErrorsList = memo<PackageGenericErrorsListProps>(
|
|||
const globalEndpointErrors = useMemo(() => {
|
||||
const errors: PackageActionFormatter[] = [];
|
||||
packageErrors.forEach((unit) => {
|
||||
if (unit.payload && unit.payload.error) {
|
||||
if (unit.status === 'failed') {
|
||||
errors.push(
|
||||
new PackageActionFormatter(
|
||||
unit.payload.error.code,
|
||||
unit.payload.error.message,
|
||||
unit,
|
||||
docLinks.links.securitySolution.packageActionTroubleshooting
|
||||
)
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue