mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-13 11:35:51 +01:00
Lightning: Catch and display external service errors
Prevent crashes like in #3700 and display the error to the user.
This commit is contained in:
parent
4cacc2a9e6
commit
26025b564e
4 changed files with 27 additions and 8 deletions
|
@ -7,6 +7,5 @@ namespace BTCPayServer.Configuration
|
|||
{
|
||||
public Dictionary<string, Uri> OtherExternalServices { get; set; } = new Dictionary<string, Uri>();
|
||||
public ExternalServices ExternalServices { get; set; } = new ExternalServices();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,13 +49,24 @@ namespace BTCPayServer.Controllers
|
|||
{
|
||||
var services = _externalServiceOptions.Value.ExternalServices.ToList()
|
||||
.Where(service => _externalServiceTypes.Contains(service.Type))
|
||||
.Select(async service => new AdditionalServiceViewModel
|
||||
.Select(async service =>
|
||||
{
|
||||
DisplayName = service.DisplayName,
|
||||
ServiceName = service.ServiceName,
|
||||
CryptoCode = service.CryptoCode,
|
||||
Type = service.Type.ToString(),
|
||||
Link = await GetServiceLink(service)
|
||||
var model = new AdditionalServiceViewModel
|
||||
{
|
||||
DisplayName = service.DisplayName,
|
||||
ServiceName = service.ServiceName,
|
||||
CryptoCode = service.CryptoCode,
|
||||
Type = service.Type.ToString()
|
||||
};
|
||||
try
|
||||
{
|
||||
model.Link = await GetServiceLink(service);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
model.Error = exception.Message;
|
||||
}
|
||||
return model;
|
||||
})
|
||||
.Select(t => t.Result)
|
||||
.ToList();
|
||||
|
|
|
@ -7,4 +7,5 @@ public class AdditionalServiceViewModel
|
|||
public string ServiceName { get; set; }
|
||||
public string CryptoCode { get; set; }
|
||||
public string Link { get; set; }
|
||||
public string Error { get; set; }
|
||||
}
|
||||
|
|
|
@ -45,7 +45,15 @@
|
|||
<div id="Services" class="services-list">
|
||||
@foreach (var service in Model.Services)
|
||||
{
|
||||
@if (string.IsNullOrEmpty(service.Link))
|
||||
@if (!string.IsNullOrEmpty(service.Error))
|
||||
{
|
||||
<div class="service" id="@($"Service-{service.ServiceName}")">
|
||||
<img src="@($"~/img/{service.Type.ToLower()}.png")" asp-append-version="true" alt="@service.DisplayName" />
|
||||
<h6>@service.DisplayName</h6>
|
||||
<small class="d-block mt-3 lh-sm fw-semibold text-danger">@service.Error</small>
|
||||
</div>
|
||||
}
|
||||
else if (string.IsNullOrEmpty(service.Link))
|
||||
{
|
||||
<a asp-controller="UIServer" asp-action="Service" asp-route-serviceName="@service.ServiceName" asp-route-cryptoCode="@service.CryptoCode" class="service" id="@($"Service-{service.ServiceName}")">
|
||||
<img src="@($"~/img/{service.Type.ToLower()}.png")" asp-append-version="true" alt="@service.DisplayName" />
|
||||
|
|
Loading…
Add table
Reference in a new issue