Skip to content

Commit

Permalink
Add error handling to top-level pages; filter out index_not_found_exc…
Browse files Browse the repository at this point in the history
…eption (#129) (#130)

Signed-off-by: Tyler Ohlsen <[email protected]>
(cherry picked from commit 292874d)

Co-authored-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and ohltyler authored Apr 8, 2024
1 parent 34a58ea commit fa7ff85
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 24 deletions.
1 change: 1 addition & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ export const FETCH_ALL_QUERY_BODY = {
},
size: 1000,
};
export const INDEX_NOT_FOUND_EXCEPTION = 'index_not_found_exception';
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ export function TextField(props: TextFieldProps) {
placeholder={props.field.placeholder || ''}
compressed={false}
value={field.value || getInitialValue(props.field.type)}
onChange={(e) => form.setFieldValue(formField, e.target.value)}
// This is a design decision to only trigger form updates onBlur() instead
// of onChange(). This is to rate limit the number of updates & re-renders made, as users
// typically rapidly type things into a text box, which would consequently trigger
// onChange() much more often.
onBlur={() => props.onFormChange()}
onChange={(e) => {
form.setFieldValue(formField, e.target.value);
props.onFormChange();
}}
/>
</EuiFormRow>
);
Expand Down
13 changes: 5 additions & 8 deletions public/pages/workflow_detail/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React from 'react';
import {
EuiPageHeader,
EuiButton,
EuiLoadingSpinner,
EuiFlexGroup,
EuiFlexItem,
EuiText,
Expand All @@ -26,13 +25,11 @@ interface WorkflowDetailHeaderProps {

export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
function getTitle() {
return props.workflow ? (
props.workflow.name
) : props.isNewWorkflow && !props.workflow ? (
DEFAULT_NEW_WORKFLOW_NAME
) : (
<EuiLoadingSpinner size="xl" />
);
return props.workflow
? props.workflow.name
: props.isNewWorkflow && !props.workflow
? DEFAULT_NEW_WORKFLOW_NAME
: '';
}

function getState() {
Expand Down
10 changes: 9 additions & 1 deletion public/pages/workflow_detail/workflow_detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function replaceActiveTab(activeTab: string, props: WorkflowDetailProps) {

export function WorkflowDetail(props: WorkflowDetailProps) {
const dispatch = useAppDispatch();
const { workflows, cachedWorkflow } = useSelector(
const { workflows, cachedWorkflow, errorMessage } = useSelector(
(state: AppState) => state.workflows
);

Expand Down Expand Up @@ -115,6 +115,14 @@ export function WorkflowDetail(props: WorkflowDetailProps) {
dispatch(searchModels(FETCH_ALL_QUERY_BODY));
}, []);

// Show a toast if an error message exists in state
useEffect(() => {
if (errorMessage) {
console.error(errorMessage);
getCore().notifications.toasts.addDanger(errorMessage);
}
}, [errorMessage]);

const tabs = [
{
id: WORKFLOW_DETAILS_TAB.EDITOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
setIsDeprovisioning(false);
})
.catch((error: any) => {
// TODO: process error (toast msg?)
console.log('error: ', error);
setIsDeprovisioning(false);
});
} else {
Expand All @@ -369,8 +367,6 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
setIsProvisioning(false);
})
.catch((error: any) => {
// TODO: process error (toast msg?)
console.log('error: ', error);
setIsProvisioning(false);
});
} else {
Expand Down Expand Up @@ -407,8 +403,6 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
setIsSaving(false);
})
.catch((error: any) => {
// TODO: process error (toast msg?)
console.log('error: ', error);
setIsSaving(false);
});
} else {
Expand All @@ -420,8 +414,6 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
history.go(0);
})
.catch((error: any) => {
// TODO: process error (toast msg?)
console.log('error: ', error);
setIsSaving(false);
});
}
Expand Down
10 changes: 9 additions & 1 deletion public/pages/workflows/workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function replaceActiveTab(activeTab: string, props: WorkflowsProps) {
*/
export function Workflows(props: WorkflowsProps) {
const dispatch = useAppDispatch();
const { workflows, loading } = useSelector(
const { workflows, loading, errorMessage } = useSelector(
(state: AppState) => state.workflows
);

Expand Down Expand Up @@ -84,6 +84,14 @@ export function Workflows(props: WorkflowsProps) {
]);
});

// Show a toast if an error message exists in state
useEffect(() => {
if (errorMessage) {
console.error(errorMessage);
getCore().notifications.toasts.addDanger(errorMessage);
}
}, [errorMessage]);

// On initial render: fetch all workflows
useEffect(() => {
dispatch(searchWorkflows(FETCH_ALL_QUERY_BODY));
Expand Down
5 changes: 5 additions & 0 deletions server/routes/flow_framework_routes_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import {
UPDATE_WORKFLOW_NODE_API_PATH,
WORKFLOW_STATE,
Workflow,
WorkflowDict,
WorkflowTemplate,
validateWorkflowTemplate,
} from '../../common';
import {
generateCustomError,
getWorkflowStateFromResponse,
getWorkflowsFromResponses,
isIgnorableError,
} from './helpers';

/**
Expand Down Expand Up @@ -196,6 +198,9 @@ export class FlowFrameworkRoutesService {
);
return res.ok({ body: { workflows: workflowDict } });
} catch (err: any) {
if (isIgnorableError(err)) {
return res.ok({ body: { workflows: {} as WorkflowDict } });
}
return generateCustomError(res, err);
}
};
Expand Down
6 changes: 6 additions & 0 deletions server/routes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {
DEFAULT_NEW_WORKFLOW_STATE_TYPE,
INDEX_NOT_FOUND_EXCEPTION,
Model,
ModelDict,
WORKFLOW_STATE,
Expand All @@ -26,6 +27,11 @@ export function generateCustomError(res: any, err: any) {
});
}

// Helper fn to filter out backend errors that we don't want to propagate on the frontend.
export function isIgnorableError(error: any): boolean {
return error.body?.error?.type === INDEX_NOT_FOUND_EXCEPTION;
}

function toWorkflowObj(workflowHit: any): Workflow {
// TODO: update schema parsing after hit schema has been updated.
// https://github.com/opensearch-project/flow-framework/issues/546
Expand Down

0 comments on commit fa7ff85

Please sign in to comment.