Skip to content

Commit

Permalink
Show correct error message for not found workflows (#768)
Browse files Browse the repository at this point in the history
Move the error boundary to be above the Layout.js to catch status badge errors
Map 400 errors that happens on misconfiguring archival to 404
Ignore emitting 404 responses as Errors
Create an error component for workflows page
  • Loading branch information
Assem-Hafez authored Dec 30, 2024
1 parent 5205d7a commit 2930dfc
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 28 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use client';
import WorkflowPageError from '@/views/workflow-page/workflow-page-error/workflow-page-error';

export default WorkflowPageError;
46 changes: 32 additions & 14 deletions src/route-handlers/describe-workflow/describe-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,39 @@ export default async function describeWorkflow(
};
return NextResponse.json(res);
} catch (e) {
logger.error<RouteHandlerErrorPayload>(
{ requestParams: decodedParams, cause: e },
'Error fetching workflow execution info'
);
// skips logs for NotFound errors
// treat 400 responses for requesting unconfigured archives as 404
if (
e instanceof GRPCError &&
(e.httpStatusCode === 404 ||
(e.httpStatusCode === 400 &&
e.message ===
'Requested workflow history not found, may have passed retention period.'))
) {
return NextResponse.json(
{
message: 'Requested workflow history not found',
cause: e,
},
{ status: 404 }
);
} else {
logger.error<RouteHandlerErrorPayload>(
{ requestParams: decodedParams, cause: e },
'Error fetching workflow execution info'
);

return NextResponse.json(
{
message:
e instanceof GRPCError
? e.message
: 'Error fetching workflow execution info',
cause: e,
},
{ status: getHTTPStatusCode(e) }
);
return NextResponse.json(
{
message:
e instanceof GRPCError
? e.message
: 'Error fetching workflow execution info',
cause: e,
},
{ status: getHTTPStatusCode(e) }
);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';

import { render, screen } from '@/test-utils/rtl';

import { RequestError } from '@/utils/request/request-error';

import WorkflowPageError from '../workflow-page-error';

jest.mock('next/navigation', () => ({
...jest.requireActual('next/navigation'),
useParams: () => ({
domain: 'test-domain',
cluster: 'test-cluster',
}),
}));

jest.mock('@/components/error-panel/error-panel', () =>
jest.fn(({ message }: { message: string }) => <div>{message}</div>)
);

describe(WorkflowPageError.name, () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('renders error page correctly', () => {
render(
<WorkflowPageError
error={new Error('something bad happened')}
reset={() => {}}
/>
);
expect(screen.getByText('Failed to load workflow')).toBeInTheDocument();
});

it('renders "not found" error page correctly', () => {
render(
<WorkflowPageError
error={new RequestError('Could not find workflow', 404)}
reset={() => {}}
/>
);
expect(
screen.getByText(
'Workflow was not found, it may have passed retention period'
)
).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use client';
import { useParams } from 'next/navigation';

import ErrorPanel from '@/components/error-panel/error-panel';
import { RequestError } from '@/utils/request/request-error';

import { type Props } from './workflow-page-error.types';

export default function WorkflowPageError({ error, reset }: Props) {
const { domain, cluster } = useParams();

if (error instanceof RequestError && error.status === 404) {
return (
<ErrorPanel
error={error}
message={`Workflow was not found, it may have passed retention period`}
actions={[
{
kind: 'link-internal',
label: 'Go to domain page',
link: `/domains/${domain}/${cluster}`,
},
]}
reset={reset}
omitLogging={true}
/>
);
}

return (
<ErrorPanel
error={error}
message="Failed to load workflow"
actions={[
{
kind: 'retry',
label: 'Retry',
},
]}
reset={reset}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type Props = {
error: Error;
reset: () => void;
};

0 comments on commit 2930dfc

Please sign in to comment.