Skip to content

Commit 7ddceeb

Browse files
[9.2] [Cases][Connector] Improve IBM error message (#244012) (#244084)
# Backport This will backport the following commits from `main` to `9.2`: - [[Cases][Connector] Improve IBM error message (#244012)](#244012) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Jan Monschke","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-11-25T06:34:17Z","message":"[Cases][Connector] Improve IBM error message (#244012)\n\n## Summary\n\nAddresses: https://github.com/elastic/kibana/issues/243994\n\nImproves the error message when the connector fails:\n\nBefore:\n<img width=\"1083\" height=\"407\" alt=\"Screenshot 2025-11-24 at 15 16 55\"\nsrc=\"https://github.com/user-attachments/assets/a8efb8c7-96ce-43a1-a349-27683f31bb97\"\n/>\n\n\nAfter:\n<img width=\"1119\" height=\"580\" alt=\"Screenshot 2025-11-24 at 15 57 38\"\nsrc=\"https://github.com/user-attachments/assets/e2b282a4-5255-4e72-9644-455416f8efaf\"\n/>","sha":"82bd200a76f5b43cb75e04bb932d218035aba25c","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","backport:version","Team:Cases","v9.2.0","v9.3.0"],"title":"[Cases][Connector] Improve IBM error message","number":244012,"url":"https://github.com/elastic/kibana/pull/244012","mergeCommit":{"message":"[Cases][Connector] Improve IBM error message (#244012)\n\n## Summary\n\nAddresses: https://github.com/elastic/kibana/issues/243994\n\nImproves the error message when the connector fails:\n\nBefore:\n<img width=\"1083\" height=\"407\" alt=\"Screenshot 2025-11-24 at 15 16 55\"\nsrc=\"https://github.com/user-attachments/assets/a8efb8c7-96ce-43a1-a349-27683f31bb97\"\n/>\n\n\nAfter:\n<img width=\"1119\" height=\"580\" alt=\"Screenshot 2025-11-24 at 15 57 38\"\nsrc=\"https://github.com/user-attachments/assets/e2b282a4-5255-4e72-9644-455416f8efaf\"\n/>","sha":"82bd200a76f5b43cb75e04bb932d218035aba25c"}},"sourceBranch":"main","suggestedTargetBranches":["9.2"],"targetPullRequestStates":[{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/244012","number":244012,"mergeCommit":{"message":"[Cases][Connector] Improve IBM error message (#244012)\n\n## Summary\n\nAddresses: https://github.com/elastic/kibana/issues/243994\n\nImproves the error message when the connector fails:\n\nBefore:\n<img width=\"1083\" height=\"407\" alt=\"Screenshot 2025-11-24 at 15 16 55\"\nsrc=\"https://github.com/user-attachments/assets/a8efb8c7-96ce-43a1-a349-27683f31bb97\"\n/>\n\n\nAfter:\n<img width=\"1119\" height=\"580\" alt=\"Screenshot 2025-11-24 at 15 57 38\"\nsrc=\"https://github.com/user-attachments/assets/e2b282a4-5255-4e72-9644-455416f8efaf\"\n/>","sha":"82bd200a76f5b43cb75e04bb932d218035aba25c"}}]}] BACKPORT--> Co-authored-by: Jan Monschke <[email protected]>
1 parent c6cdd99 commit 7ddceeb

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

x-pack/platform/plugins/shared/stack_connectors/server/connector_types/resilient/resilient.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* 2.0.
66
*/
77

8+
import { AxiosError, type AxiosResponse } from 'axios';
89
import { request, createAxiosResponse } from '@kbn/actions-plugin/server/lib/axios_utils';
910
import { loggingSystemMock } from '@kbn/core/server/mocks';
1011
import { resilientFields, incidentTypes, severity } from './mocks';
@@ -173,6 +174,32 @@ describe('IBM Resilient connector', () => {
173174
'Unable to get incident with id 1. Error: An error has occurred'
174175
);
175176
});
177+
178+
it('should read message from response body if available', async () => {
179+
requestMock.mockImplementation(() => {
180+
const err = new AxiosError('An error has occurred');
181+
err.response = {
182+
status: 400,
183+
data: { message: 'A test error message' },
184+
} as AxiosResponse;
185+
throw err;
186+
});
187+
188+
await expect(
189+
connector.createIncident(
190+
{
191+
name: 'title',
192+
description: 'desc',
193+
incidentTypes: [1001],
194+
severityCode: 6,
195+
additionalFields: null,
196+
},
197+
connectorUsageCollector
198+
)
199+
).rejects.toThrow(
200+
'[Action][IBM Resilient]: Unable to create incident. Error: Status code: 400. Message: API Error: A test error message.'
201+
);
202+
});
176203
});
177204

178205
describe('createIncident', () => {

x-pack/platform/plugins/shared/stack_connectors/server/connector_types/resilient/resilient.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import type { AxiosError } from 'axios';
9-
import { omitBy, isNil } from 'lodash/fp';
9+
import { omitBy, isNil, isObject } from 'lodash/fp';
1010
import type { ServiceParams } from '@kbn/actions-plugin/server';
1111
import { CaseConnector, getBasicAuthHeader } from '@kbn/actions-plugin/server';
1212
import type { Type } from '@kbn/config-schema';
@@ -76,6 +76,9 @@ export class ResilientConnector extends CaseConnector<
7676
if (error.response.status === 401) {
7777
return i18n.UNAUTHORIZED_API_ERROR;
7878
}
79+
if (isObject(error.response?.data) && 'message' in error.response.data) {
80+
return `API Error: ${error.response.data.message}`;
81+
}
7982
return `API Error: ${error.response?.statusText}`;
8083
}
8184

0 commit comments

Comments
 (0)