Skip to content

Commit bcadd67

Browse files
shahzad31NicholasPeretti
authored andcommitted
[Synthetics] Return 404 status code for monitor not found instead of 500 (elastic#238418)
## Summary Return 404 status code for monitor not found instead of 500 , this is especially broken for read-only user.
1 parent 9b02d70 commit bcadd67

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
selectEncryptedSyntheticsSavedMonitors,
1616
selectMonitorListState,
1717
selectorMonitorDetailsState,
18-
selectorError,
18+
selectSyntheticsMonitorError,
1919
} from '../../../state';
2020
import { useGetUrlParams } from '../../../hooks';
2121

@@ -37,7 +37,7 @@ export const useSelectedMonitor = ({
3737
() => monitorsList.find((monitor) => monitor[ConfigKey.CONFIG_ID] === monitorId) ?? null,
3838
[monitorId, monitorsList]
3939
);
40-
const error = useSelector(selectorError);
40+
const error = useSelector(selectSyntheticsMonitorError);
4141
const { lastRefresh, refreshInterval } = useSyntheticsRefreshContext();
4242
const { syntheticsMonitor, syntheticsMonitorLoading, syntheticsMonitorDispatchedAt } =
4343
useSelector(selectorMonitorDetailsState);

x-pack/solutions/observability/plugins/synthetics/server/services/monitor_config_repository.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type { EncryptedSavedObjectsClient } from '@kbn/encrypted-saved-objects-p
2020
import { withApmSpan } from '@kbn/apm-data-access-plugin/server/utils/with_apm_span';
2121
import { isEmpty, isEqual } from 'lodash';
2222
import type { Logger } from '@kbn/logging';
23+
import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server';
2324
import { MONITOR_SEARCH_FIELDS } from '../routes/common';
2425
import {
2526
legacyMonitorAttributes,
@@ -65,7 +66,10 @@ export class MonitorConfigRepository {
6566
]);
6667
const resolved = results.saved_objects.find((obj) => obj?.attributes);
6768
if (!resolved) {
68-
throw new Error('Monitor not found');
69+
throw SavedObjectsErrorHelpers.createGenericNotFoundError(
70+
syntheticsMonitorSavedObjectType,
71+
id
72+
);
6973
}
7074
return resolved;
7175
}

0 commit comments

Comments
 (0)