Skip to content

Commit 894e635

Browse files
committed
feat(v1-contexts): Host rejections in actions
1 parent 6519251 commit 894e635

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/v1-contexts/src/remote.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
ContextSchema,
55
ContextSchemaList,
66
EventMap,
7+
Rejection,
78
RejectionHandler,
89
ActionList,
910
ActionSchema,
@@ -103,7 +104,7 @@ export const defineActions = <ID extends string, S extends ActionSchema>(
103104
return () => {
104105
const invoker = useInvoker()
105106
const endpoint = invoker.endpoint as Endpoint<{
106-
invoke (name: string, ...args: unknown[]): Promise<unknown>
107+
invoke (name: string, ...args: unknown[]): Promise<{ payload: unknown, rejection: Rejection | null }>
107108
}>
108109

109110
return (new Proxy({}, {
@@ -120,11 +121,15 @@ export const defineActions = <ID extends string, S extends ActionSchema>(
120121
}
121122

122123
const result = await endpoint.call.invoke(String(name), ...args)
123-
if (!expects(result)) {
124+
if (result.rejection) {
125+
throw new Error(`[crm:embed:remote] Invokable ${String(name)} in schema ${id} failed with: ${result.rejection.message}`)
126+
}
127+
128+
if (!expects(result.payload)) {
124129
throw new Error(`[crm:embed:remote] Invalid result for invokable ${String(name)} in schema ${id}`)
125130
}
126131

127-
return result
132+
return result.payload
128133
}
129134
},
130135
}) as ActionList<S>)

0 commit comments

Comments
 (0)