Skip to content

Commit ad610f6

Browse files
committed
feat: added error handling for schema parsing
1 parent 251cdc7 commit ad610f6

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

frontend/src/components/pages/rp-connect/utils/schema.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { ConnectError } from '@connectrpc/connect';
12
import {
23
type ComponentList,
34
type ComponentSpec,
45
ComponentStatus,
56
} from 'protogen/redpanda/api/dataplane/v1/pipeline_pb';
7+
import { toast } from 'sonner';
68
import { onboardingWizardStore } from 'state/onboarding-wizard-store';
9+
import { formatToastErrorMessageGRPC } from 'utils/toast.utils';
710

811
import {
912
hasWizardRelevantFields,
@@ -74,15 +77,28 @@ const typeToYamlConfigKey: Record<Exclude<ConnectComponentType, 'custom'>, Conne
7477
/**
7578
* Parses ComponentList from API response into ConnectComponentSpec array.
7679
* Converts proto ComponentSpec to strongly-typed ConnectComponentSpec by overriding the type field.
80+
* Returns empty array and shows toast notification on error.
7781
*/
78-
export const parseSchema = (componentList: ComponentList): ConnectComponentSpec[] =>
79-
Object.entries(COMPONENT_TYPE_MAPPINGS).flatMap(([componentType, { listKey }]) =>
80-
((componentList[listKey] as ComponentSpec[]) || []).map((comp) => ({
81-
...comp,
82-
type: componentType as Exclude<ConnectComponentType, 'custom'>,
83-
config: comp.config,
84-
}))
85-
);
82+
export function parseSchema(componentList: ComponentList): ConnectComponentSpec[] {
83+
try {
84+
return Object.entries(COMPONENT_TYPE_MAPPINGS).flatMap(([componentType, { listKey }]) =>
85+
((componentList[listKey] as ComponentSpec[]) || []).map((comp) => ({
86+
...comp,
87+
type: componentType as Exclude<ConnectComponentType, 'custom'>,
88+
config: comp.config,
89+
}))
90+
);
91+
} catch (error) {
92+
toast.error(
93+
formatToastErrorMessageGRPC({
94+
error: ConnectError.from(error),
95+
action: 'Parse component schema',
96+
entity: 'Component list',
97+
})
98+
);
99+
return [];
100+
}
101+
}
86102

87103
const generateRedpandaTopLevelConfig = (): Record<string, unknown> => {
88104
const userData = onboardingWizardStore.getUserData();

0 commit comments

Comments
 (0)