Skip to content

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

@chunfan-3t

Description

@chunfan-3t

@ 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)
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions