Skip to content

Commit 6b1e420

Browse files
committed
Code formatting and use const for error handling
1 parent e26705a commit 6b1e420

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/Umbraco.Cms.Integrations.Crm.Hubspot.Core/Controllers/FormsController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public async Task<ResponseDto> GetAll()
7777
try
7878
{
7979
var requestMessage = CreateRequest(hubspotApiKey);
80-
80+
8181
var response = await ClientFactory().SendAsync(requestMessage);
8282

8383
responseContent = await response.Content.ReadAsStringAsync();
@@ -240,7 +240,7 @@ public async Task<ResponseDto> ValidateAccessToken()
240240
{
241241
// Attempt to refresh the access token
242242
var refreshAccessTokenResponse = await _authorizationService.RefreshAccessTokenAsync();
243-
if (string.IsNullOrEmpty(refreshAccessTokenResponse) || refreshAccessTokenResponse == "error")
243+
if (string.IsNullOrEmpty(refreshAccessTokenResponse) || refreshAccessTokenResponse == BaseAuthorizationService.ErrorPrefix)
244244
{
245245
return new ResponseDto
246246
{

src/Umbraco.Cms.Integrations.Crm.Hubspot.Core/Services/AuthorizationService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public async Task<string> GetAccessTokenAsync(string code)
6868
var errorResult = await response.Content.ReadAsStringAsync();
6969
var errorDto = JsonConvert.DeserializeObject<ErrorDto>(errorResult);
7070

71-
return "Error: " + errorDto.Message;
71+
return string.Format("{0}: {1}", ErrorPrefix, errorDto.Message);
7272
}
7373

74-
return "Error: An unexpected error occurred.";
74+
return string.Format("{0}: An unexpected error occurred.", ErrorPrefix);
7575
}
7676

7777
public string RefreshAccessToken() =>
@@ -83,9 +83,9 @@ public async Task<string> RefreshAccessTokenAsync()
8383

8484
var data = new Dictionary<string, string>
8585
{
86-
{"grant_type", "refresh_token"},
87-
{"client_id", _oauthSettings.ClientId },
88-
{"client_secret", _oauthSettings.ClientSecret },
86+
{ "grant_type", "refresh_token" },
87+
{ "client_id", _oauthSettings.ClientId },
88+
{ "client_secret", _oauthSettings.ClientSecret },
8989
{ "refresh_token", refreshToken }
9090
};
9191

@@ -109,7 +109,7 @@ public async Task<string> RefreshAccessTokenAsync()
109109
return result;
110110
}
111111

112-
return "error";
112+
return ErrorPrefix;
113113
}
114114
}
115115
}

src/Umbraco.Cms.Integrations.Crm.Hubspot.Core/Services/BaseAuthorizationService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class BaseAuthorizationService
1818

1919
protected readonly ITokenService TokenService;
2020

21+
public const string ErrorPrefix = "Error";
22+
2123
public BaseAuthorizationService(ITokenService tokenService)
2224
{
2325
TokenService = tokenService;

src/Umbraco.Cms.Integrations.Crm.Hubspot.Core/Services/UmbracoAuthorizationService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public async Task<string> GetAccessTokenAsync(string code)
7575
var errorResult = await response.Content.ReadAsStringAsync();
7676
var errorDto = JsonConvert.DeserializeObject<ErrorDto>(errorResult);
7777

78-
return "Error: " + errorDto.Message;
78+
return string.Format("{0}: {1}", ErrorPrefix, errorDto.Message);
7979
}
8080

81-
return "Error: An unexpected error occurred.";
81+
return string.Format("{0}: An unexpected error occurred.", ErrorPrefix);
8282
}
8383

8484
public string RefreshAccessToken() =>
@@ -90,8 +90,8 @@ public async Task<string> RefreshAccessTokenAsync()
9090

9191
var data = new Dictionary<string, string>
9292
{
93-
{"grant_type", "refresh_token"},
94-
{"client_id", ClientId },
93+
{ "grant_type", "refresh_token" },
94+
{ "client_id", ClientId },
9595
{ "refresh_token", refreshToken }
9696
};
9797

@@ -116,7 +116,7 @@ public async Task<string> RefreshAccessTokenAsync()
116116
return result;
117117
}
118118

119-
return "error";
119+
return ErrorPrefix;
120120
}
121121
}
122122
}

0 commit comments

Comments
 (0)