File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ import { PlexusInstance } from './instance/instance'
2+
13export 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+ }
You can’t perform that action at this time.
0 commit comments