Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handler errors no being sent to subprocess #784

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno-runtime/lib/accessors/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class AppAccessors {
params,
})
.then((response) => response.result)
.catch((err) => err.error);
.catch((err) => { throw new Error(err.error) });
},
},
) as T;
Expand Down
26 changes: 15 additions & 11 deletions deno-runtime/lib/accessors/modify/ModifyCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const { RocketChatAssociationModel } = require('@rocket.chat/apps-engine/definit
};

export class ModifyCreator implements IModifyCreator {
constructor(private readonly senderFn: typeof Messenger.sendRequest) {}
constructor(private readonly senderFn: typeof Messenger.sendRequest) { }

getLivechatCreator(): ILivechatCreator {
return new Proxy(
Expand All @@ -56,7 +56,9 @@ export class ModifyCreator implements IModifyCreator {
params,
})
.then((response) => response.result)
.catch((err) => err.error);
.catch((err) => {
throw new Error(err.error);
});
},
},
) as ILivechatCreator;
Expand All @@ -68,15 +70,17 @@ export class ModifyCreator implements IModifyCreator {
{
get:
(_target: unknown, prop: string) =>
(...params: unknown[]) =>
prop === 'toJSON'
? {}
: this.senderFn({
method: `accessor:getModifier:getCreator:getUploadCreator:${prop}`,
params,
})
.then((response) => response.result)
.catch((err) => err.error),
(...params: unknown[]) =>
prop === 'toJSON'
? {}
: this.senderFn({
method: `accessor:getModifier:getCreator:getUploadCreator:${prop}`,
params,
})
.then((response) => response.result)
.catch((err) => {
throw new Error(err.error);
}),
},
) as IUploadCreator;
}
Expand Down
42 changes: 23 additions & 19 deletions deno-runtime/lib/accessors/modify/ModifyUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ const { RocketChatAssociationModel } = require('@rocket.chat/apps-engine/definit
};

export class ModifyUpdater implements IModifyUpdater {
constructor(private readonly senderFn: typeof Messenger.sendRequest) {}
constructor(private readonly senderFn: typeof Messenger.sendRequest) { }

public getLivechatUpdater(): ILivechatUpdater {
return new Proxy(
{ __kind: 'getLivechatUpdater' },
{
get:
(_target: unknown, prop: string) =>
(...params: unknown[]) =>
prop === 'toJSON'
? {}
: this.senderFn({
method: `accessor:getModifier:getUpdater:getLivechatUpdater:${prop}`,
params,
})
.then((response) => response.result)
.catch((err) => err.error),
(...params: unknown[]) =>
prop === 'toJSON'
? {}
: this.senderFn({
method: `accessor:getModifier:getUpdater:getLivechatUpdater:${prop}`,
params,
})
.then((response) => response.result)
.catch((err) => {
throw new Error(err.error);
}),
},
) as ILivechatUpdater;
}
Expand All @@ -53,15 +55,17 @@ export class ModifyUpdater implements IModifyUpdater {
{
get:
(_target: unknown, prop: string) =>
(...params: unknown[]) =>
prop === 'toJSON'
? {}
: this.senderFn({
method: `accessor:getModifier:getUpdater:getUserUpdater:${prop}`,
params,
})
.then((response) => response.result)
.catch((err) => err.error),
(...params: unknown[]) =>
prop === 'toJSON'
? {}
: this.senderFn({
method: `accessor:getModifier:getUpdater:getUserUpdater:${prop}`,
params,
})
.then((response) => response.result)
.catch((err) => {
throw new Error(err.error);
}),
},
) as IUserUpdater;
}
Expand Down
16 changes: 14 additions & 2 deletions src/server/runtime/deno/AppsEngineDenoRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,27 @@ export class DenoRuntimeSubprocessController extends EventEmitter {
const { method } = message.payload;

if (method.startsWith('accessor:')) {
const result = await this.handleAccessorMessage(message as jsonrpc.IParsedObjectRequest);
let result: jsonrpc.SuccessObject | jsonrpc.ErrorObject;

try {
result = await this.handleAccessorMessage(message as jsonrpc.IParsedObjectRequest);
} catch (e) {
result = jsonrpc.error((message.payload as jsonrpc.RequestObject).id, new jsonrpc.JsonRpcError(e.message, 1000));
}

this.messenger.send(result);

return;
}

if (method.startsWith('bridges:')) {
const result = await this.handleBridgeMessage(message as jsonrpc.IParsedObjectRequest);
let result: jsonrpc.SuccessObject | jsonrpc.ErrorObject;

try {
result = await this.handleBridgeMessage(message as jsonrpc.IParsedObjectRequest);
} catch (e) {
result = jsonrpc.error((message.payload as jsonrpc.RequestObject).id, new jsonrpc.JsonRpcError(e.message, 1000));
}

this.messenger.send(result);

Expand Down
Loading