Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get workflow rest api #668

18 changes: 16 additions & 2 deletions src/route-handlers/get-workflow-history/get-workflow-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
type RouteParams,
type RequestParams,
} from './get-workflow-history.types';
import getWorkflowHistoryQueryParamSchema from './schemas/get-workflow-history-query-params-schema';
import getWorkflowHistoryQueryParamsSchema from './schemas/get-workflow-history-query-params-schema';

export default async function getWorkflowHistory(
request: NextRequest,
requestParams: RequestParams
) {
const decodedParams = decodeUrlParams<RouteParams>(requestParams.params);
const { data: queryParams, error } =
getWorkflowHistoryQueryParamSchema.safeParse(
getWorkflowHistoryQueryParamsSchema.safeParse(
Object.fromEntries(request.nextUrl.searchParams)
);

Expand Down Expand Up @@ -49,6 +49,20 @@ export default async function getWorkflowHistory(

return Response.json(res);
} catch (e) {
if (
e instanceof GRPCError &&
e.message ===
'Requested workflow history not found, may have passed retention period.'
) {
return NextResponse.json(
{
message: 'Workflow not found',
cause: e,
},
{ status: 404 }
);
}

logger.error<RouteHandlerErrorPayload>(
{ requestParams: decodedParams, cause: e },
'Error fetching workflow history'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod';

const getWorkflowHistoryQueryParamSchema = z.object({
const getWorkflowHistoryQueryParamsSchema = z.object({
pageSize: z
.string()
.transform((val) => parseInt(val, 10))
Expand All @@ -16,4 +16,4 @@ const getWorkflowHistoryQueryParamSchema = z.object({
.optional(),
});

export default getWorkflowHistoryQueryParamSchema;
export default getWorkflowHistoryQueryParamsSchema;
Loading