@@ -78,27 +78,38 @@ export default class VerifyDevForumRank extends Component {
7878
7979 async getRobloxUsername ( discordId : Snowflake , guildId : Snowflake ) : Promise < string | null > {
8080 const endpoint = this . formatApiEndpoint ( discordId , guildId ) ;
81- const response = await fetch ( endpoint , {
81+ const idResponse = await fetch ( endpoint , {
8282 headers : {
8383 // eslint-disable-next-line @typescript-eslint/naming-convention
8484 Authorization : `Bearer ${ process . env . ROVER_API_KEY } `
8585 }
8686 } ) ;
87+ if ( ! idResponse . ok ) {
88+ Logger . error ( `Tried fetching data from Rover API: ${ idResponse . status } ${ idResponse . statusText } ` ) ;
89+ return null ;
90+ }
8791
88- if ( ! response . ok ) {
89- Logger . error ( `Tried fetching data from Rover API: ${ response . status } ${ response . statusText } ` ) ;
92+ const idData = await idResponse . json ( ) ;
93+ // Validate the response format
94+ if ( ! idData || typeof idData !== "object" || ! ( "robloxId" in idData ) || typeof idData . robloxId !== "number" ) {
95+ Logger . error ( `Unknown response format from Rover API. Expected number: data.robloxId, received: ${ JSON . stringify ( idData ) } ` ) ;
9096 return null ;
9197 }
9298
93- const data = await response . json ( ) ;
99+ const usernameResponse = await fetch ( `https://users.roblox.com/v1/users/${ idData . robloxId } ` ) ;
100+ if ( ! usernameResponse . ok ) {
101+ Logger . error ( `Tried fetching data from Roblox API: ${ usernameResponse . status } ${ usernameResponse . statusText } ` ) ;
102+ return null ;
103+ }
94104
105+ const usernameData = await usernameResponse . json ( ) ;
95106 // Validate the response format
96- if ( ! data || typeof data !== "object" || ! ( "cachedUsername " in data ) || typeof data . cachedUsername !== "string" ) {
97- Logger . error ( `Unknown response format from Rover API. Expected string: data.cachedUsername , received: ${ JSON . stringify ( data ) } ` ) ;
107+ if ( ! usernameData || typeof usernameData !== "object" || ! ( "name " in usernameData ) || typeof usernameData . name !== "string" ) {
108+ Logger . error ( `Unknown response format from Roblox API. Expected string: data.name , received: ${ JSON . stringify ( usernameData ) } ` ) ;
98109 return null ;
99110 }
100111
101- return data . cachedUsername ;
112+ return usernameData . name ;
102113 }
103114
104115 formatApiEndpoint ( discordId : Snowflake , guildId : Snowflake ) : `https://registry.rover.link/api/guilds/${string } /discord-to-roblox/${string } ` {
0 commit comments