Skip to content
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

Got unexpected status code 502 when updating token via 'oauth2/token' #537

Open
chunfan-3t opened this issue Feb 23, 2024 · 0 comments
Open

Comments

@chunfan-3t
Copy link

@ amplify/backend/function/amplifyIdentityBrokerToken/src/index.js

else if (grant_type === "refresh_token") {
		
    var cognitoResponse = await cognitoSP.initiateAuth(params).promise(); // Call Cognito with refresh token to get refreshed id and access tokens
    var access_token = cognitoResponse.AuthenticationResult.AccessToken;
    var id_token = cognitoResponse.AuthenticationResult.IdToken;

}

The promise of cognitoSP.initiateAuth(params) may throw an error.
IMO, we should add a try catch to properly handle this.

try {
    var cognitoResponse = await cognitoSP.initiateAuth(params).promise();
} catch (error) {
    const errorBody = {
        errorType: error. errorType,
        errorMessage: error. errorMessage,
        time: error.time,
            ...
        stack: error.stack
    }
    return {
        statusCode: error.statusCode,
        body: JSON.stringify(errorBody)
    };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant