[8.x] [Rule details page] Fix Cannot read properties of undefined (reading 'statusCode') (#206023) (#206472)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Rule details page] Fix Cannot read properties of undefined (reading
'statusCode')
(#206023)](https://github.com/elastic/kibana/pull/206023)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"maryam.saeidi@elastic.co"},"sourceCommit":{"committedDate":"2025-01-13T16:09:15Z","message":"[Rule
details page] Fix Cannot read properties of undefined (reading
'statusCode') (#206023)\n\n## Summary\r\n\r\nOccasionally, we see the
following error on the Observability rule\r\ndetails
page:\r\n\r\n```\r\nTypeError: Cannot read properties of undefined
(reading 'statusCode')\r\n```\r\n\r\nThis PR tries to fix this issue in
order to capture the actual error and\r\navoid accessing `statusCode`
when the error.body is
undefined.","sha":"25e12a644501c9844ef3bbf4af8923ca30c0529e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor"],"title":"[Rule
details page] Fix Cannot read properties of undefined (reading
'statusCode')","number":206023,"url":"https://github.com/elastic/kibana/pull/206023","mergeCommit":{"message":"[Rule
details page] Fix Cannot read properties of undefined (reading
'statusCode') (#206023)\n\n## Summary\r\n\r\nOccasionally, we see the
following error on the Observability rule\r\ndetails
page:\r\n\r\n```\r\nTypeError: Cannot read properties of undefined
(reading 'statusCode')\r\n```\r\n\r\nThis PR tries to fix this issue in
order to capture the actual error and\r\navoid accessing `statusCode`
when the error.body is
undefined.","sha":"25e12a644501c9844ef3bbf4af8923ca30c0529e"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206023","number":206023,"mergeCommit":{"message":"[Rule
details page] Fix Cannot read properties of undefined (reading
'statusCode') (#206023)\n\n## Summary\r\n\r\nOccasionally, we see the
following error on the Observability rule\r\ndetails
page:\r\n\r\n```\r\nTypeError: Cannot read properties of undefined
(reading 'statusCode')\r\n```\r\n\r\nThis PR tries to fix this issue in
order to capture the actual error and\r\navoid accessing `statusCode`
when the error.body is
undefined.","sha":"25e12a644501c9844ef3bbf4af8923ca30c0529e"}}]}]
BACKPORT-->

Co-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>
This commit is contained in:
Kibana Machine 2025-01-14 04:47:53 +11:00 committed by GitHub
parent 408c761f9c
commit 56ea9a5bf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View file

@ -61,7 +61,7 @@ export function useLoadRuleEventLogs(props: UseLoadRuleEventLogsProps) {
retry: 0,
refetchOnWindowFocus: false,
});
const hasExceedLogs = useMemo(() => error && error.body.statusCode === 413, [error]);
const hasExceedLogs = useMemo(() => error && error.body?.statusCode === 413, [error]);
return useMemo(
() => ({
data,

View file

@ -109,7 +109,7 @@ export const RuleEventLogListKPI = (props: RuleEventLogListKPIProps) => {
});
setKpi(newKpi);
} catch (e) {
if (e.body.statusCode === 413) {
if (e.body?.statusCode === 413) {
return;
}
toasts.addDanger({

View file

@ -201,7 +201,7 @@ export const RuleEventLogListTable = <T extends RuleEventLogListOptions>(
const onError = useCallback<NonNullable<UseLoadRuleEventLogsProps['onError']>>(
(e) => {
if (e.body.statusCode === 413) {
if (e.body?.statusCode === 413) {
return;
}
notifications.toasts.addDanger({