Skip to content

Commit

Permalink
[APM] Add fallback for missing handled value
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Mar 8, 2019
1 parent d2e16b5 commit f48a0cd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { shallow } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';
import React from 'react';
import { APMError } from 'x-pack/plugins/apm/typings/es_schemas/Error';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { IStickyProperty } from '../../../shared/StickyProperties';
import { StickyErrorProperties } from './StickyErrorProperties';

describe('StickyErrorProperties', () => {
Expand Down Expand Up @@ -41,4 +42,44 @@ describe('StickyErrorProperties', () => {

expect(wrapper).toMatchSnapshot();
});

describe('error.exception.handled', () => {
function getIsHandledValue(error: APMError) {
const wrapper = shallow(
<StickyErrorProperties error={error} transaction={undefined} />
);

const stickyProps = wrapper.prop('stickyProperties') as IStickyProperty[];
const handledProp = stickyProps.find(
prop => prop.fieldName === 'error.exception.handled'
) as IStickyProperty;

return handledProp.val;
}

it('should should render "true"', () => {
const error = {
error: { exception: [{ handled: true }] }
} as APMError;

const isHandledValue = getIsHandledValue(error);
expect(isHandledValue).toBe('true');
});

it('should should render "false"', () => {
const error = {
error: { exception: [{ handled: false }] }
} as APMError;

const isHandledValue = getIsHandledValue(error);
expect(isHandledValue).toBe('false');
});

it('should should render "N/A"', () => {
const error = {} as APMError;

const isHandledValue = getIsHandledValue(error);
expect(isHandledValue).toBe('N/A');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { i18n } from '@kbn/i18n';
import { isBoolean } from 'lodash';
import React, { Fragment } from 'react';
import {
ERROR_EXC_HANDLED,
Expand Down Expand Up @@ -56,6 +57,7 @@ function TransactionLink({ error, transaction }: Props) {
}

export function StickyErrorProperties({ error, transaction }: Props) {
const isHandled = idx(error, _ => _.error.exception[0].handled);
const stickyProperties = [
{
fieldName: '@timestamp',
Expand Down Expand Up @@ -88,9 +90,7 @@ export function StickyErrorProperties({ error, transaction }: Props) {
label: i18n.translate('xpack.apm.errorGroupDetails.handledLabel', {
defaultMessage: 'Handled'
}),
val:
String(idx(error, _ => _.error.exception[0].handled)) ||
NOT_AVAILABLE_LABEL,
val: isBoolean(isHandled) ? String(isHandled) : NOT_AVAILABLE_LABEL,
width: '25%'
},
{
Expand Down

0 comments on commit f48a0cd

Please sign in to comment.