aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-02-21 16:44:37 -0800
committerAdam Soltys <[email protected]>2023-02-21 16:44:37 -0800
commit2346e4824a406d6cb797a034d91bb5d1b321bbfc (patch)
treee045920944b029e5e5e45b59f6d462dc90f172f4
parent7d4f1ae952f3230c5a020ed9c4afe3c968ac099f (diff)
downloadcoinos-server-2346e4824a406d6cb797a034d91bb5d1b321bbfc.tar.gz
coinos-server-2346e4824a406d6cb797a034d91bb5d1b321bbfc.zip
bail on missing pot
-rw-r--r--lib/utils.js2
-rw-r--r--routes/payments.js4
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 8291d173..da95b5ad 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -22,6 +22,8 @@ export const fail = msg => {
throw new Error(msg);
};
+export const bail = (res, msg) => res.code(500).send(msg);
+
export const SATS = 100000000;
export const sats = n => Math.round(n * SATS);
export const btc = n => parseFloat((n / SATS).toFixed(8));
diff --git a/routes/payments.js b/routes/payments.js
index e0372092..a6b10994 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -4,7 +4,7 @@ import { emit } from "$lib/sockets";
import { v4 } from "uuid";
import { db, g, s, t } from "$lib/db";
import { l, err } from "$lib/logging";
-import { fail, btc, sats } from "$lib/utils";
+import { bail, fail, btc, sats } from "$lib/utils";
import { requirePin } from "$lib/auth";
import { debit, credit, confirm, types } from "$lib/payments";
import got from "got";
@@ -143,7 +143,7 @@ export default {
async pot({ params: { name } }, res) {
let amount = await g(`pot:${name}`);
- if (!amount) fail("pot not found");
+ if (!amount) return bail(res, "pot not found");
let payments = (await db.lRange(`pot:${name}:payments`, 0, -1)) || [];
payments = await Promise.all(payments.map(hash => g(`payment:${hash}`)));