mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'improve-errors' into 'main'
Improve signer timeout errors See merge request soapbox-pub/ditto!412
This commit is contained in:
commit
ed067e541e
3 changed files with 60 additions and 6 deletions
|
|
@ -1,6 +1,11 @@
|
||||||
import { ErrorHandler } from '@hono/hono';
|
import { ErrorHandler } from '@hono/hono';
|
||||||
|
import { HTTPException } from '@hono/hono/http-exception';
|
||||||
|
|
||||||
export const errorHandler: ErrorHandler = (err, c) => {
|
export const errorHandler: ErrorHandler = (err, c) => {
|
||||||
|
if (err instanceof HTTPException) {
|
||||||
|
return c.json({ error: err.message }, err.status);
|
||||||
|
}
|
||||||
|
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
if (err.message === 'canceling statement due to statement timeout') {
|
if (err.message === 'canceling statement due to statement timeout') {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
// deno-lint-ignore-file require-await
|
// deno-lint-ignore-file require-await
|
||||||
|
import { HTTPException } from '@hono/hono/http-exception';
|
||||||
import { NConnectSigner, NostrEvent, NostrSigner } from '@nostrify/nostrify';
|
import { NConnectSigner, NostrEvent, NostrSigner } from '@nostrify/nostrify';
|
||||||
|
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
|
|
@ -27,30 +28,78 @@ export class ConnectSigner implements NostrSigner {
|
||||||
|
|
||||||
async signEvent(event: Omit<NostrEvent, 'id' | 'pubkey' | 'sig'>): Promise<NostrEvent> {
|
async signEvent(event: Omit<NostrEvent, 'id' | 'pubkey' | 'sig'>): Promise<NostrEvent> {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
return signer.signEvent(event);
|
try {
|
||||||
|
return await signer.signEvent(event);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.name === 'AbortError') {
|
||||||
|
throw new HTTPException(408, { message: 'The event was not signed quickly enough' });
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly nip04 = {
|
readonly nip04 = {
|
||||||
encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
|
encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
return signer.nip04.encrypt(pubkey, plaintext);
|
try {
|
||||||
|
return await signer.nip04.encrypt(pubkey, plaintext);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.name === 'AbortError') {
|
||||||
|
throw new HTTPException(408, {
|
||||||
|
message: 'Text was not encrypted quickly enough',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
|
decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
return signer.nip04.decrypt(pubkey, ciphertext);
|
try {
|
||||||
|
return await signer.nip04.decrypt(pubkey, ciphertext);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.name === 'AbortError') {
|
||||||
|
throw new HTTPException(408, {
|
||||||
|
message: 'Text was not decrypted quickly enough',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly nip44 = {
|
readonly nip44 = {
|
||||||
encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
|
encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
return signer.nip44.encrypt(pubkey, plaintext);
|
try {
|
||||||
|
return await signer.nip44.encrypt(pubkey, plaintext);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.name === 'AbortError') {
|
||||||
|
throw new HTTPException(408, {
|
||||||
|
message: 'Text was not encrypted quickly enough',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
|
decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
|
||||||
const signer = await this.signer;
|
const signer = await this.signer;
|
||||||
return signer.nip44.decrypt(pubkey, ciphertext);
|
try {
|
||||||
|
return await signer.nip44.decrypt(pubkey, ciphertext);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.name === 'AbortError') {
|
||||||
|
throw new HTTPException(408, {
|
||||||
|
message: 'Text was not decrypted quickly enough',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ export class ReadOnlySigner implements NostrSigner {
|
||||||
|
|
||||||
async signEvent(): Promise<NostrEvent> {
|
async signEvent(): Promise<NostrEvent> {
|
||||||
throw new HTTPException(401, {
|
throw new HTTPException(401, {
|
||||||
message: 'Log out and back in',
|
message: 'Log in with Nostr Connect to sign events',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue