Remove InvoiceLookupError
Docker / build-and-push-image (backend, backend, coracle/caravel-backend) (push) Failing after 0s
Docker / build-and-push-image (frontend, frontend, coracle/caravel-frontend) (push) Failing after 1s

This commit is contained in:
Jon Staab
2026-05-19 17:29:47 -07:00
parent 2d5eb0ca84
commit b49d62f1dd
3 changed files with 32 additions and 78 deletions
+7 -20
View File
@@ -1,11 +1,9 @@
use std::sync::Arc;
use axum::extract::{Path, State};
use reqwest::StatusCode;
use crate::api::{Api, AuthedPubkey};
use crate::stripe::InvoiceLookupError;
use crate::web::{ApiError, ApiResult, bad_request, internal, not_found, ok};
use crate::web::{ApiResult, bad_request, internal, not_found, ok};
pub async fn list_tenant_invoices(
State(api): State<Arc<Api>>,
@@ -32,14 +30,15 @@ pub async fn get_invoice(
.billing
.get_invoice_with_tenant(&id)
.await
.map_err(map_invoice_lookup_error)?;
.map_err(internal)?
.ok_or_else(|| not_found("invoice not found"))?;
api.require_admin_or_tenant(&auth, &tenant.pubkey)?;
let invoice = api
.billing
.reconcile_manual_lightning_invoice(&id, &invoice)
.await
.map_err(map_invoice_lookup_error)?;
.map_err(internal)?;
ok(invoice)
}
@@ -53,14 +52,15 @@ pub async fn get_invoice_bolt11(
.billing
.get_invoice_with_tenant(&id)
.await
.map_err(map_invoice_lookup_error)?;
.map_err(internal)?
.ok_or_else(|| not_found("invoice not found"))?;
api.require_admin_or_tenant(&auth, &tenant.pubkey)?;
let invoice = api
.billing
.reconcile_manual_lightning_invoice(&id, &invoice)
.await
.map_err(map_invoice_lookup_error)?;
.map_err(internal)?;
let status = invoice["status"].as_str().unwrap_or_default();
if status != "open" {
@@ -77,16 +77,3 @@ pub async fn get_invoice_bolt11(
.map_err(internal)?;
ok(serde_json::json!({ "bolt11": bolt11 }))
}
fn map_invoice_lookup_error(error: InvoiceLookupError) -> ApiError {
match error {
InvoiceLookupError::StripeClient { status } => match status {
StatusCode::NOT_FOUND => not_found("invoice not found"),
_ => {
tracing::warn!(%status, "stripe invoice request returned unexpected status");
internal("invoice request rejected")
}
},
InvoiceLookupError::Internal(error) => internal(error),
}
}