aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-08-06 23:01:26 -0700
committerAdam Soltys <[email protected]>2025-08-06 23:01:26 -0700
commitd85cc4db731e8cd0b93f64f63ed861716d4b2e04 (patch)
treefccef60796bf2bdb7cd5b8cfd6b7a23674606817 /routes
parentf1fa75ee43bad1f9c5ea06f4160cfee9847a035f (diff)
downloadcoinos-server-d85cc4db731e8cd0b93f64f63ed861716d4b2e04.tar.gz
coinos-server-d85cc4db731e8cd0b93f64f63ed861716d4b2e04.zip
fail on undefined invoice
Diffstat (limited to 'routes')
-rw-r--r--routes/invoices.ts27
1 files changed, 16 insertions, 11 deletions
diff --git a/routes/invoices.ts b/routes/invoices.ts
index 6c2f713d..013cedba 100644
--- a/routes/invoices.ts
+++ b/routes/invoices.ts
@@ -2,24 +2,29 @@ import config from "$config";
import { db } from "$lib/db";
import { generate } from "$lib/invoices";
import { err } from "$lib/logging";
-import { bail, fields, getInvoice, getUser } from "$lib/utils";
+import { bail, fail, fields, getInvoice, getUser } from "$lib/utils";
import rpc from "@coinos/rpc";
export default {
async get(req, res) {
- const {
- params: { id },
- } = req;
- const invoice = await getInvoice(id);
+ try {
+ const {
+ params: { id },
+ } = req;
+ if (id === "undefined") fail("invalid id");
+ const invoice = await getInvoice(id);
- if (invoice) {
- invoice.secret = undefined;
- invoice.user = await getUser(invoice.uid, fields);
+ if (invoice) {
+ invoice.secret = undefined;
+ invoice.user = await getUser(invoice.uid, fields);
- invoice.items ||= [];
+ invoice.items ||= [];
+ }
+ if (invoice) res.send(invoice);
+ else fail("invoice not found");
+ } catch (e) {
+ bail(res, e.message);
}
- if (invoice) res.send(invoice);
- else res.code(500).send("invoice not found");
},
async create(req, res) {