refactor(errors): put in constants
This commit is contained in:
@@ -3,6 +3,7 @@ import { useMemo } from 'react';
|
||||
import { MarkerType } from '../../types';
|
||||
import type { EdgeMarker } from '../../types';
|
||||
import { useStoreApi } from '../../hooks/useStore';
|
||||
import { errorMessages } from '../../contants';
|
||||
|
||||
type SymbolProps = Omit<EdgeMarker, 'type'>;
|
||||
|
||||
@@ -43,7 +44,7 @@ export function useMarkerSymbol(type: MarkerType) {
|
||||
const symbolExists = Object.prototype.hasOwnProperty.call(MarkerSymbols, type);
|
||||
|
||||
if (!symbolExists) {
|
||||
store.getState().onError?.('009', `Marker type "${type}" doesn't exist.`);
|
||||
store.getState().onError?.('009', errorMessages['009'](type));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { getEdgePositions, getHandle, getNodeData } from './utils';
|
||||
import { GraphViewProps } from '../GraphView';
|
||||
import { ConnectionMode, Position } from '../../types';
|
||||
import type { Edge, ReactFlowState } from '../../types';
|
||||
import { errorMessages } from '../../contants';
|
||||
|
||||
type EdgeRendererProps = Pick<
|
||||
GraphViewProps,
|
||||
@@ -98,7 +99,7 @@ const EdgeRenderer = ({
|
||||
let edgeType = edge.type || 'default';
|
||||
|
||||
if (!edgeTypes[edgeType]) {
|
||||
onError?.('003', `Edge type "${edgeType}" not found. Using fallback type "default".`);
|
||||
onError?.('011', errorMessages['011'](edgeType));
|
||||
edgeType = 'default';
|
||||
}
|
||||
|
||||
@@ -115,12 +116,7 @@ const EdgeRenderer = ({
|
||||
const isFocusable = !!(edge.focusable || (edgesFocusable && typeof edge.focusable === 'undefined'));
|
||||
|
||||
if (!sourceHandle || !targetHandle) {
|
||||
onError?.(
|
||||
'008',
|
||||
`Couldn't create edge for ${!sourceHandle ? 'source' : 'target'} handle id: "${
|
||||
!sourceHandle ? edge.sourceHandle : edge.targetHandle
|
||||
}", edge id: ${edge.id}.`
|
||||
);
|
||||
onError?.('008', errorMessages['008'](sourceHandle, edge));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user