@@ -124,29 +124,28 @@ private async void buttonMastodonAuth_Click(object sender, EventArgs e)
124124 if ( ! Uri . TryCreate ( instanceUriStr , UriKind . Absolute , out var instanceUri ) )
125125 return ;
126126
127- var application = await Mastodon . RegisterClientAsync ( instanceUri ) ;
127+ try
128+ {
129+ var application = await Mastodon . RegisterClientAsync ( instanceUri ) ;
128130
129- var authorizeUri = Mastodon . GetAuthorizeUri ( instanceUri , application . ClientId ) ;
131+ var authorizeUri = Mastodon . GetAuthorizeUri ( instanceUri , application . ClientId ) ;
130132
131- var code = AuthDialog . DoAuth ( this , authorizeUri ) ;
132- if ( string . IsNullOrEmpty ( code ) )
133- return ;
133+ var code = AuthDialog . DoAuth ( this , authorizeUri ) ;
134+ if ( string . IsNullOrEmpty ( code ) )
135+ return ;
134136
135- string accessToken ;
136- try
137- {
138- accessToken = await Mastodon . GetAccessTokenAsync ( instanceUri , application . ClientId , application . ClientSecret , code ) ;
137+ var accessToken = await Mastodon . GetAccessTokenAsync ( instanceUri , application . ClientId , application . ClientSecret , code ) ;
138+
139+ this . mastodonCredential = await Mastodon . VerifyCredentialAsync ( instanceUri , accessToken ) ;
140+
141+ this . RefreshMastodonCredential ( ) ;
139142 }
140143 catch ( WebApiException ex )
141144 {
142145 var message = Properties . Resources . AuthorizeButton_Click2 + Environment . NewLine + ex . Message ;
143146 MessageBox . Show ( this , message , "Authenticate" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
144147 return ;
145148 }
146-
147- this . mastodonCredential = await Mastodon . VerifyCredentialAsync ( instanceUri , accessToken ) ;
148-
149- this . RefreshMastodonCredential ( ) ;
150149 }
151150 }
152151}
0 commit comments