Skip to content

Commit 038d924

Browse files
committed
Add try/catch in .then handlers
1 parent 53eaf23 commit 038d924

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

library/sinks/AwsSDKVersion3.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ export class AwsSDKVersion3 implements Wrapper {
7676
returnValue instanceof Promise &&
7777
args[0] instanceof exports.InvokeModelCommand
7878
) {
79+
// Inspect the response after the promise resolves, it won't change the original promise
7980
returnValue.then((response) => {
80-
this.processResponse(response, agent);
81+
try {
82+
this.processResponse(response, agent);
83+
} catch {
84+
// If we don't catch these errors, it will result in an unhandled promise rejection!
85+
}
8186
});
8287
}
8388
}

library/sinks/OpenAI.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ export class OpenAI implements Wrapper {
5959
kind: "ai_op",
6060
modifyReturnValue: (args, returnValue, agent) => {
6161
if (returnValue instanceof Promise) {
62+
// Inspect the response after the promise resolves, it won't change the original promise
6263
returnValue.then((response) => {
63-
this.inspectResponse(agent, response);
64+
try {
65+
this.inspectResponse(agent, response);
66+
} catch {
67+
// If we don't catch these errors, it will result in an unhandled promise rejection!
68+
}
6469
});
6570
}
6671

0 commit comments

Comments
 (0)