Skip to content

Commit

Permalink
fix: handler errors no being sent to subprocess (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gubert committed Jul 29, 2024
1 parent 4bb6dec commit 52805ec
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
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

0 comments on commit 52805ec

Please sign in to comment.