aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-29 10:11:25 +0000
committerAdam Soltys <[email protected]>2023-12-29 10:12:10 +0000
commitc474dbb763480ec923cd49f5cac0e07a310552a7 (patch)
tree7376dece597eaea7999e732f83b44cfdfe521c1c
parent46522875683db9123f8a6fe9746a5c5db6f1638e (diff)
downloadcoinos-server-c474dbb763480ec923cd49f5cac0e07a310552a7.tar.gz
coinos-server-c474dbb763480ec923cd49f5cac0e07a310552a7.zip
error handling
-rw-r--r--lib/migrate.js9
-rw-r--r--routes/lnurl.js1
-rw-r--r--routes/nostr.js6
3 files changed, 13 insertions, 3 deletions
diff --git a/lib/migrate.js b/lib/migrate.js
index 20d26325..87e7ab60 100644
--- a/lib/migrate.js
+++ b/lib/migrate.js
@@ -1,4 +1,4 @@
-import { err } from "$lib/logging";
+import { err, l } from "$lib/logging";
import { types } from "$lib/payments";
import { archive, db, g } from "$lib/db";
@@ -15,6 +15,7 @@ async function migrate(id) {
if (user) {
let { username } = user;
username = username.replace(/\s/g, "").toLowerCase();
+ l("migrating", username);
let multi = await db
.multi()
.set(`user:${username}`, id)
@@ -59,7 +60,11 @@ async function migrate(id) {
}),
);
- await multi.exec();
+ try {
+ await multi.exec();
+ } catch (e) {
+ warn("failed to migrate", username);
+ }
delete q[id];
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 79bac995..81a74991 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -78,6 +78,7 @@ export default {
async lnurl({ params: { id }, query: { amount, nostr } }, res) {
let uid = await g(`lnurl:${id}`);
let user = await g(`user:${uid}`);
+ if (!user) user = await migrate(uid);
let { username } = user;
username = username.replace(/\s/g, "").toLowerCase();
diff --git a/routes/nostr.js b/routes/nostr.js
index 990317a9..2137150e 100644
--- a/routes/nostr.js
+++ b/routes/nostr.js
@@ -94,6 +94,7 @@ export default {
},
async follows({ params: { pubkey }, query: { tagsonly } }, res) {
+ try {
let sub = `${pubkey}:follows`,
params = {
limit: 1,
@@ -131,9 +132,12 @@ export default {
}
follows = uniq(follows, (e) => e.pubkey);
- follows.sort((a, b) => a.username.localeCompare(b.username));
+ follows.sort((a, b) => a.username && a.username.localeCompare(b.username));
res.send(follows);
+ } catch(e) {
+ bail(res, e.message);
+ }
},
async followers({ params: { pubkey } }, res) {