mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
API: Handle lightning invoice creation errors (#2070)
Catches LightningClient exceptions and responds with a detailed API error (400) instead of a generic server failure (503).
This commit is contained in:
@@ -263,13 +263,29 @@ namespace BTCPayServer.Controllers.GreenField
|
||||
{
|
||||
return this.CreateValidationError(ModelState);
|
||||
}
|
||||
var invoice = await lightningClient.CreateInvoice(
|
||||
new CreateInvoiceParams(request.Amount, request.Description, request.Expiry)
|
||||
|
||||
try
|
||||
{
|
||||
var invoice = await lightningClient.CreateInvoice(
|
||||
new CreateInvoiceParams(request.Amount, request.Description, request.Expiry)
|
||||
{
|
||||
PrivateRouteHints = request.PrivateRouteHints
|
||||
},
|
||||
CancellationToken.None);
|
||||
return Ok(ToModel(invoice));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var nameSpace = ex.GetType().Namespace;
|
||||
var isLnClientError = nameSpace != null &&
|
||||
nameSpace.StartsWith("BTCPayServer.Lightning",
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
if (isLnClientError)
|
||||
{
|
||||
PrivateRouteHints = request.PrivateRouteHints
|
||||
},
|
||||
CancellationToken.None);
|
||||
return Ok(ToModel(invoice));
|
||||
return this.CreateAPIError("invoice-error", ex.Message);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private LightningInvoiceData ToModel(LightningInvoice invoice)
|
||||
|
||||
Reference in New Issue
Block a user