[Synthetics] Refactor screenshot block route to not return 404 !! (#210656)

## Summary

Refactor screenshot block route to not return 404 !!

Route will return empty list instead of 404 for missing screenshot
blocks !!

This also updates to enable _inspect on route !!

### Testing
Screenshot still works as expected 

<img width="1728" alt="image"
src="https://github.com/user-attachments/assets/9a2b887d-9091-4bff-97e6-3c0775e6f6bd"
/>
This commit is contained in:
Shahzad 2025-02-13 12:11:13 +01:00 committed by GitHub
parent 211165524f
commit 159910d06f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 37 deletions

View file

@ -24,9 +24,13 @@ export interface FetchJourneyStepsParams {
}
export async function fetchScreenshotBlockSet(params: string[]): Promise<ScreenshotBlockDoc[]> {
return apiService.post<ScreenshotBlockDoc[]>(SYNTHETICS_API_URLS.JOURNEY_SCREENSHOT_BLOCKS, {
hashes: params,
});
const response = await apiService.post<{ result: ScreenshotBlockDoc[] }>(
SYNTHETICS_API_URLS.JOURNEY_SCREENSHOT_BLOCKS,
{
hashes: params,
}
);
return response.result;
}
export async function fetchBrowserJourney(

View file

@ -6,13 +6,9 @@
*/
import { schema } from '@kbn/config-schema';
import { IKibanaResponse } from '@kbn/core-http-server';
import { isRight } from 'fp-ts/Either';
import * as t from 'io-ts';
import { getJourneyScreenshotBlocks } from '../../queries/get_journey_screenshot_blocks';
import { ScreenshotBlockDoc } from '../../../common/runtime_types';
import { SYNTHETICS_API_URLS } from '../../../common/constants';
import { RouteContext, SyntheticsRestApiRouteFactory } from '../types';
import { SyntheticsRestApiRouteFactory } from '../types';
export const createJourneyScreenshotBlocksRoute: SyntheticsRestApiRouteFactory = () => ({
method: 'POST',
@ -23,34 +19,16 @@ export const createJourneyScreenshotBlocksRoute: SyntheticsRestApiRouteFactory =
}),
},
writeAccess: false,
handler: (routeProps) => {
return journeyScreenshotBlocksHandler(routeProps);
handler: async ({ request, syntheticsEsClient }) => {
const { hashes: blockIds } = request.body;
const result = await getJourneyScreenshotBlocks({
blockIds,
syntheticsEsClient,
});
return {
result,
};
},
});
export const journeyScreenshotBlocksHandler = async ({
response,
request,
syntheticsEsClient,
}: RouteContext): Promise<IKibanaResponse<ScreenshotBlockDoc[]>> => {
const { hashes: blockIds } = request.body;
if (!isStringArray(blockIds)) return response.badRequest();
const result = await getJourneyScreenshotBlocks({
blockIds,
syntheticsEsClient,
});
if (result.length === 0) {
return response.notFound();
}
return response.ok({
body: result,
});
};
function isStringArray(data: unknown): data is string[] {
return isRight(t.array(t.string).decode(data));
}