diff --git a/x-pack/plugins/snapshot_restore/server/routes/api/repositories.test.ts b/x-pack/plugins/snapshot_restore/server/routes/api/repositories.test.ts index c3389e893407d..ad180b8db45e0 100644 --- a/x-pack/plugins/snapshot_restore/server/routes/api/repositories.test.ts +++ b/x-pack/plugins/snapshot_restore/server/routes/api/repositories.test.ts @@ -188,11 +188,10 @@ describe('[Snapshot and Restore API Routes] Repositories', () => { const mockEsResponse = { [name]: { type: '', settings: {} }, }; - const mockEsSnapshotError = jest.fn().mockRejectedValueOnce(new Error('snapshot error')); getClusterSettingsFn.mockResolvedValue({ body: mockSnapshotGetManagedRepositoryEsResponse }); getRepoFn.mockResolvedValue({ body: mockEsResponse }); - getSnapshotFn.mockResolvedValue({ body: mockEsSnapshotError }); + getSnapshotFn.mockRejectedValueOnce(new Error('snapshot error')); const expectedResponse = { repository: { name, ...mockEsResponse[name] }, diff --git a/x-pack/plugins/snapshot_restore/server/routes/api/repositories.ts b/x-pack/plugins/snapshot_restore/server/routes/api/repositories.ts index 4898c6e299ad3..a0799f4de8c92 100644 --- a/x-pack/plugins/snapshot_restore/server/routes/api/repositories.ts +++ b/x-pack/plugins/snapshot_restore/server/routes/api/repositories.ts @@ -6,7 +6,10 @@ */ import { TypeOf } from '@kbn/config-schema'; -import type { SnapshotRepositorySettings } from '@elastic/elasticsearch/api/types'; +import type { + SnapshotGetRepositoryResponse, + SnapshotRepositorySettings, +} from '@elastic/elasticsearch/api/types'; import { DEFAULT_REPOSITORY_TYPES, REPOSITORY_PLUGINS_MAP } from '../../../common/constants'; import { Repository, RepositoryType } from '../../../common/types'; @@ -101,7 +104,7 @@ export function registerRepositoriesRoutes({ const managedRepository = await getManagedRepositoryName(clusterClient.asCurrentUser); - let repositoryByName: any; + let repositoryByName: SnapshotGetRepositoryResponse; try { ({ body: repositoryByName } = await clusterClient.asCurrentUser.snapshot.getRepository({ @@ -111,12 +114,18 @@ export function registerRepositoriesRoutes({ return handleEsError({ error: e, response: res }); } - const response = await clusterClient.asCurrentUser.snapshot.get({ - repository: name, - snapshot: '_all', - }); - - const { snapshots: snapshotList } = response.body; + const { + body: { snapshots: snapshotList }, + } = await clusterClient.asCurrentUser.snapshot + .get({ + repository: name, + snapshot: '_all', + }) + .catch((e) => ({ + body: { + snapshots: null, + }, + })); if (repositoryByName[name]) { const { type = '', settings = {} } = repositoryByName[name];