Skip to content

Commit 95acc79

Browse files
ManolachiHinton
andauthored
Log swallowed HttpRequestExceptions (#1866)
Co-authored-by: Hinton <oscar@oscarhinton.com>
1 parent 0e88720 commit 95acc79

File tree

8 files changed

+27
-15
lines changed

8 files changed

+27
-15
lines changed

bitwarden_license/src/Sso/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"internalAdmin": "http://localhost:62911",
1212
"internalIdentity": "http://localhost:33656",
1313
"internalApi": "http://localhost:4000",
14-
"internalVault": "http://localhost:4001",
14+
"internalVault": "https://localhost:8080",
1515
"internalSso": "http://localhost:51822"
1616
},
1717
"events": {

src/Admin/Controllers/HomeController.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
using Bit.Admin.Models;
77
using Bit.Core.Settings;
88
using Microsoft.AspNetCore.Authorization;
9+
using Microsoft.AspNetCore.Http;
910
using Microsoft.AspNetCore.Mvc;
11+
using Microsoft.Extensions.Logging;
1012

1113
namespace Bit.Admin.Controllers
1214
{
1315
public class HomeController : Controller
1416
{
1517
private readonly GlobalSettings _globalSettings;
16-
private HttpClient _httpClient = new HttpClient();
18+
private readonly HttpClient _httpClient = new HttpClient();
19+
private readonly ILogger<HomeController> _logger;
1720

18-
public HomeController(GlobalSettings globalSettings)
21+
public HomeController(GlobalSettings globalSettings, ILogger<HomeController> logger)
1922
{
2023
_globalSettings = globalSettings;
24+
_logger = logger;
2125
}
2226

2327
[Authorize]
@@ -40,10 +44,10 @@ public IActionResult Error()
4044

4145
public async Task<IActionResult> GetLatestDockerHubVersion(string repository, CancellationToken cancellationToken)
4246
{
47+
var requestUri = $"https://hub.docker.com/v2/repositories/bitwarden/{repository}/tags/";
4348
try
4449
{
45-
var response = await _httpClient.GetAsync(
46-
$"https://hub.docker.com/v2/repositories/bitwarden/{repository}/tags/", cancellationToken);
50+
var response = await _httpClient.GetAsync(requestUri, cancellationToken);
4751
if (response.IsSuccessStatusCode)
4852
{
4953
using var jsonDocument = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync(cancellationToken), cancellationToken: cancellationToken);
@@ -60,25 +64,33 @@ public async Task<IActionResult> GetLatestDockerHubVersion(string repository, Ca
6064
}
6165
}
6266
}
63-
catch (HttpRequestException) { }
67+
catch (HttpRequestException e)
68+
{
69+
_logger.LogError(e, $"Error encountered while sending GET request to {requestUri}");
70+
return new JsonResult("Unable to fetch latest version") { StatusCode = StatusCodes.Status500InternalServerError };
71+
}
6472

6573
return new JsonResult("-");
6674
}
6775

6876
public async Task<IActionResult> GetInstalledWebVersion(CancellationToken cancellationToken)
6977
{
78+
var requestUri = $"{_globalSettings.BaseServiceUri.InternalVault}/version.json";
7079
try
7180
{
72-
var response = await _httpClient.GetAsync(
73-
$"{_globalSettings.BaseServiceUri.InternalVault}/version.json", cancellationToken);
81+
var response = await _httpClient.GetAsync(requestUri, cancellationToken);
7482
if (response.IsSuccessStatusCode)
7583
{
7684
using var jsonDocument = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync(cancellationToken), cancellationToken: cancellationToken);
7785
var root = jsonDocument.RootElement;
7886
return new JsonResult(root.GetProperty("version").GetString());
7987
}
8088
}
81-
catch (HttpRequestException) { }
89+
catch (HttpRequestException e)
90+
{
91+
_logger.LogError(e, $"Error encountered while sending GET request to {requestUri}");
92+
return new JsonResult("Unable to fetch installed version") { StatusCode = StatusCodes.Status500InternalServerError };
93+
}
8294

8395
return new JsonResult("-");
8496
}

src/Admin/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"internalAdmin": "http://localhost:62911",
1212
"internalIdentity": "http://localhost:33656",
1313
"internalApi": "http://localhost:4000",
14-
"internalVault": "http://localhost:4001",
14+
"internalVault": "https://localhost:8080",
1515
"internalSso": "http://localhost:51822"
1616
},
1717
"mail": {

src/Api/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"internalAdmin": "http://localhost:62911",
1212
"internalIdentity": "http://localhost:33656",
1313
"internalApi": "http://localhost:4000",
14-
"internalVault": "http://localhost:4001",
14+
"internalVault": "https://localhost:8080",
1515
"internalSso": "http://localhost:51822"
1616
},
1717
"mail": {

src/Billing/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"internalAdmin": "http://localhost:62911",
1212
"internalIdentity": "http://localhost:33656",
1313
"internalApi": "http://localhost:4000",
14-
"internalVault": "http://localhost:4001",
14+
"internalVault": "https://localhost:8080",
1515
"internalSso": "http://localhost:51822"
1616
},
1717
"mail": {

src/Events/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"internalAdmin": "http://localhost:62911",
1212
"internalIdentity": "http://localhost:33656",
1313
"internalApi": "http://localhost:4000",
14-
"internalVault": "http://localhost:4001",
14+
"internalVault": "https://localhost:8080",
1515
"internalSso": "http://localhost:51822"
1616
},
1717
"events": {

src/Identity/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"internalAdmin": "http://localhost:62911",
1212
"internalIdentity": "http://localhost:33656",
1313
"internalApi": "http://localhost:4000",
14-
"internalVault": "http://localhost:4001",
14+
"internalVault": "https://localhost:8080",
1515
"internalSso": "http://localhost:51822"
1616
},
1717
"attachment": {

src/Notifications/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"internalAdmin": "http://localhost:62911",
1212
"internalIdentity": "http://localhost:33656",
1313
"internalApi": "http://localhost:4000",
14-
"internalVault": "http://localhost:4001",
14+
"internalVault": "https://localhost:8080",
1515
"internalSso": "http://localhost:51822"
1616
},
1717
"notifications": {

0 commit comments

Comments
 (0)