Skip to content

Commit

Permalink
log errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nad-au committed May 3, 2024
1 parent 520459e commit e5f644e
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions monorepo/actionstep-auth/src/action-step-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,24 @@ export const actionStepAuth = (
},
callback: async (code: string): Promise<ActionStepToken> => {
logger?.debug('Callback with code:', code)
accessToken = await authCode.getToken({
code,
redirect_uri,
scope,
})
try {
accessToken = await authCode.getToken({
code,
redirect_uri,
scope,
})
} catch (error) {
if (error instanceof Error) {
logger?.error(
'Error obtaining token from code:',
JSON.stringify(error),
)
} else {
logger?.error('Error obtaining token from code:', error)
}
throw error
}

logger?.debug('Got accessToken:', accessToken)

const actionStepToken = toActionStepToken(accessToken.token)
Expand Down Expand Up @@ -76,9 +89,17 @@ export const actionStepAuth = (

if (accessToken.expired() || forceRefresh) {
logger?.debug(`Token is expired. Refreshing...`)
accessToken = scope
? await accessToken.refresh({ scope })
: await accessToken.refresh()
try {
accessToken = await accessToken.refresh({ scope })
} catch (error) {
if (error instanceof Error) {
logger?.error('Error refreshing token:', JSON.stringify(error))
} else {
logger?.error('Error refreshing token:', error)
}
throw error
}

logger?.debug(`Storing refreshed access token ${accessToken}`)
if (store) {
const storedToken = toActionStepToken(accessToken.token)
Expand Down

0 comments on commit e5f644e

Please sign in to comment.