feat(core): add vue flow error class
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
1
packages/core/src/auto-imports.d.ts
vendored
1
packages/core/src/auto-imports.d.ts
vendored
@@ -19,6 +19,7 @@ declare global {
|
||||
const Slots: typeof import('./context/index')['Slots']
|
||||
const Storage: typeof import('./composables/useVueFlow')['Storage']
|
||||
const VueFlow: typeof import('./context/index')['VueFlow']
|
||||
const VueFlowError: typeof import('./utils/log')['VueFlowError']
|
||||
const addEdge: typeof import('./utils/graph')['addEdge']
|
||||
const addEdgeToStore: typeof import('./utils/store')['addEdgeToStore']
|
||||
const applyChanges: typeof import('./utils/changes')['applyChanges']
|
||||
|
||||
@@ -16,7 +16,7 @@ export default function useEdge<Data = ElementData, CustomEvents extends Record<
|
||||
const edge = findEdge<Data, CustomEvents>(edgeId)
|
||||
|
||||
if (!edge) {
|
||||
throw new Error(`[vue-flow]: useEdge - Edge with id ${edgeId} not found!`)
|
||||
throw new VueFlowError(`Edge with id ${edgeId} not found!`, 'useEdge')
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -16,7 +16,7 @@ export default function useNode<Data = ElementData, CustomEvents extends Record<
|
||||
const node = findNode<Data, CustomEvents>(nodeId)
|
||||
|
||||
if (!node) {
|
||||
throw new Error(`[vue-flow]: useNode - Node with id ${nodeId} not found!`)
|
||||
throw new VueFlowError(`Node with id ${nodeId} not found!`, 'useNode')
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -126,7 +126,7 @@ export default (options?: FlowProps): VueFlowStore => {
|
||||
/**
|
||||
* Vue flow wasn't able to find any store instance - we can't proceed
|
||||
*/
|
||||
if (!vueFlow) throw new Error('[vueflow]: store instance not found.')
|
||||
if (!vueFlow) throw new VueFlowError('Store instance not found.', 'useVueFlow')
|
||||
|
||||
// always provide a fresh instance into context on call
|
||||
if (scope) {
|
||||
|
||||
@@ -70,4 +70,6 @@ export { default as useEdge } from './composables/useEdge'
|
||||
|
||||
export { useGetPointerPosition } from './composables/useGetPointerPosition'
|
||||
|
||||
export { VueFlowError } from './utils/log'
|
||||
|
||||
export * from './types'
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
const productionEnvs = ['production', 'prod']
|
||||
|
||||
export class VueFlowError extends Error {
|
||||
constructor(message: string, scope?: string) {
|
||||
super(`[Vue Flow]: ${scope ? `${scope} - ` : ''}${message}`)
|
||||
}
|
||||
}
|
||||
|
||||
export const warn = (message: string, ...args: any[]) => {
|
||||
if (!productionEnvs.includes(__ENV__ || '')) {
|
||||
console.warn(`[Vue Flow]: ${message}`, ...args)
|
||||
|
||||
Reference in New Issue
Block a user