-
Notifications
You must be signed in to change notification settings - Fork 12
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
chore: Improve error handling by using ErrorWithCause
#581
chore: Improve error handling by using ErrorWithCause
#581
Conversation
ErrorWithCause
sample-code/README.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some docs were missing.
Also mask grounding input should have been placed as part of the orchestration group.
@@ -196,11 +198,12 @@ export async function orchestrationInputFiltering(): Promise<void> { | |||
}); | |||
throw new Error('Input was not filtered as expected.'); | |||
} catch (error: any) { | |||
if (error.response?.status === 400) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to make these changes due to the introduction of ErrorWithCause
} | ||
}); | ||
|
||
/* Foundation Models (Azure OpenAI) */ | ||
app.get('/azure-openai/chat-completion', async (req, res) => { | ||
try { | ||
const response = await chatCompletion(); | ||
res.send(response.getContent()); | ||
res.header('Content-Type', 'text/plain').send(response.getContent()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because by default for string response, res.send
treats it like html. So line breakers \n
won't work. Instead, we should have used <br />
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, but the ## Error Handling section needs a bit more detail, so that users do not have to jump to the cloud SDK docs to understand how to use it properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would accept the breaking change, and treat that as a bug fix, as I did not know the response body was not included.
Please have a look at the suggestion for the release notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Context
Closes SAP/ai-sdk-js-backlog#235.
What this PR does and why it is needed
This PR introduces
ErrorWithCause
for all request execution usingexecuteRequest()
from core.The most useful information is contained in
error.stack
which will be by default printed out if not caught usingtry-catch
.I also have to make changes to
sample-code
since accessing response data is now a layer deeper wrapper bycause
.Also cleaned up
sample-code
a bit.Docs are added for general error handling in case of a failing request.