Skip to content

Commit

Permalink
[Rule details page] Fix Cannot read properties of undefined (reading …
Browse files Browse the repository at this point in the history
…'statusCode') (#206023)

## Summary

Occasionally, we see the following error on the Observability rule
details page:

```
TypeError: Cannot read properties of undefined (reading 'statusCode')
```

This PR tries to fix this issue in order to capture the actual error and
avoid accessing `statusCode` when the error.body is undefined.
  • Loading branch information
maryam-saeidi authored Jan 13, 2025
1 parent 0ad1695 commit 25e12a6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 25e12a6

Please sign in to comment.