Skip to content

Commit fdcd949

Browse files
committed
new general use plexus error
1 parent 7b365c4 commit fdcd949

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

packages/plexus-core/src/action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isAsyncFunction } from '@plexusjs/utils'
22
import { PlexusInstance, instance } from './instance/instance'
3-
import { PlexusError, handlePlexusError } from './error'
3+
import { handlePlexusError } from '@plexusjs/utils'
44
type ErrorHandler = (error: any) => unknown
55

66
export interface PlexusActionHooks {

packages/plexus-core/src/instance/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { handlePlexusError } from '@plexusjs/utils'
12
import type { PlexusCollectionInstance } from '../collection/collection'
23
import type { PlexusComputedStateInstance } from '../computed'
3-
import { handlePlexusError } from '../error'
44
import type { PlexusEventInstance } from '../event'
55
import type { PlexusStateInstance } from '../state'
66
import { PlexusInstance, instance } from './instance'

packages/plexus-core/src/error.ts renamed to packages/plexus-utils/src/client/error.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
import { PlexusInstance } from './instance/instance'
2-
3-
type PlexusErrorOptions = { code: string; source: string; stack: string }
1+
type PlexusErrorOptions = {
2+
code: string
3+
source: string
4+
stack: string
5+
type?: 'general' | 'api' | 'action'
6+
} & Record<'type', string>
47

58
export class PlexusError extends Error {
69
public name = 'PlexusError'
710
public error = true
11+
type = 'general'
812
constructor(
913
message: string,
1014
public options?: Partial<PlexusErrorOptions>
1115
) {
1216
super(message)
17+
if (options) {
18+
this.options = options
19+
this.type = options.type || 'general'
20+
}
1321
}
1422
// custom error format for logging and debugging
1523
toString() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './error'

packages/plexus-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './shared'
2+
export * from './client'
23

34
export * from './types'

0 commit comments

Comments
 (0)