mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-21 22:11:48 +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:
parent
fa517417ed
commit
ff87319a74
3 changed files with 42 additions and 6 deletions
|
@ -263,13 +263,29 @@ namespace BTCPayServer.Controllers.GreenField
|
||||||
{
|
{
|
||||||
return this.CreateValidationError(ModelState);
|
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
|
return this.CreateAPIError("invoice-error", ex.Message);
|
||||||
},
|
}
|
||||||
CancellationToken.None);
|
throw;
|
||||||
return Ok(ToModel(invoice));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LightningInvoiceData ToModel(LightningInvoice invoice)
|
private LightningInvoiceData ToModel(LightningInvoice invoice)
|
||||||
|
|
|
@ -433,6 +433,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Wellknown error codes are: `invoice-error`",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ProblemDetails"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"503": {
|
"503": {
|
||||||
"description": "Unable to access the lightning node"
|
"description": "Unable to access the lightning node"
|
||||||
},
|
},
|
||||||
|
|
|
@ -509,6 +509,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Wellknown error codes are: `invoice-error`",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ProblemDetails"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"503": {
|
"503": {
|
||||||
"description": "Unable to access the lightning node"
|
"description": "Unable to access the lightning node"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue