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 Zod errors in Outlook auth function #7931
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
📦 Next.js Bundle AnalysisThis analysis was generated by the next.js bundle analysis action 🤖 This PR introduced no changes to the javascript bundle 🙌 |
grant_type: "refresh_token", | ||
client_secret, | ||
}), | ||
}); | ||
const o365AuthCredentials = refreshTokenResponseSchema.parse(await handleErrorsJson(response)); | ||
const responseJson = await handleErrorsJson(response); | ||
const tokenResponse = refreshTokenResponseSchema.safeParse(responseJson); |
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.
Change to safeParse so we don't throw an error if MS sends a response we aren't expecting
const o365AuthCredentials = refreshTokenResponseSchema.parse(await handleErrorsJson(response)); | ||
const responseJson = await handleErrorsJson(response); | ||
const tokenResponse = refreshTokenResponseSchema.safeParse(responseJson); | ||
o365AuthCredentials = { ...o365AuthCredentials, ...(tokenResponse.success && tokenResponse.data) }; |
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.
If the responses is what we were expecting, update the new keys. In the spread operator, if keys are present in both objects, the second object's keys will be written
if (!tokenResponse.success) { | ||
console.error("zodError:", tokenResponse.error, "MS response:", responseJson); | ||
} |
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.
Capture the response on Axiom so we can better diagnose the problem
refreshTokenResponseSchema.safeParse(o365AuthCredentials).success && | ||
!isExpired(o365AuthCredentials.expires_in) |
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.
Refresh the tokens if the keys object is not what we expected or the access token is expired
No failed tests 🎉 |
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.
Other than that looking good 👍
What does this PR do?
This PR fixes Zod parsing errors in the Outlook auth function. By using safeParse we will not throw an error when the response from MS is not as expected. We also added increased logging of MS error responses to better handle future errors.
Fixes # (issue)
https://www.loom.com/share/3ca4e240e5864151854c50ed88431cc3
Environment: Staging(main branch) / Production
Type of change
How should this be tested?
Checklist