Skip to content

Commit d51c497

Browse files
committed
plexus errors
1 parent f301284 commit d51c497

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/plexus-core/src/error.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PlexusInstance } from './instance/instance'
2+
13
export class PlexusError extends Error {
24
public name = 'PlexusError'
35
public error = true
@@ -12,3 +14,25 @@ export class PlexusError extends Error {
1214
return `PlexusError: ${this.message} (${this.options?.code ?? 'NO_CODE'})`
1315
}
1416
}
17+
export function handlePlexusError(e: unknown | Error | string): PlexusError {
18+
if (typeof e === 'string') {
19+
return new PlexusError(e)
20+
}
21+
22+
// error-like objects
23+
if (e instanceof PlexusError) return e
24+
if (e instanceof Error) {
25+
return new PlexusError(
26+
`An error occurred during the execution of an action (${e.message})`,
27+
{ origin: 'action', stack: e.stack }
28+
)
29+
}
30+
31+
// generic error
32+
return new PlexusError(
33+
'An error occurred during the execution of an action',
34+
{
35+
origin: 'action',
36+
}
37+
)
38+
}

0 commit comments

Comments
 (0)