mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
publishEvent: publish to pool in background, catch errors and log
This commit is contained in:
parent
82446e3ef1
commit
5fec5deb06
1 changed files with 11 additions and 3 deletions
|
|
@ -12,6 +12,7 @@ import { RelayError } from '@/RelayError.ts';
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
import { nostrNow } from '@/utils.ts';
|
import { nostrNow } from '@/utils.ts';
|
||||||
import { parseFormData } from '@/utils/formdata.ts';
|
import { parseFormData } from '@/utils/formdata.ts';
|
||||||
|
import { errorJson } from '@/utils/log.ts';
|
||||||
import { purifyEvent } from '@/utils/purify.ts';
|
import { purifyEvent } from '@/utils/purify.ts';
|
||||||
|
|
||||||
/** EventTemplate with defaults. */
|
/** EventTemplate with defaults. */
|
||||||
|
|
@ -158,9 +159,16 @@ async function updateNames(k: number, d: string, n: Record<string, boolean>, c:
|
||||||
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
||||||
logi({ level: 'info', ns: 'ditto.event', source: 'api', id: event.id, kind: event.kind });
|
logi({ level: 'info', ns: 'ditto.event', source: 'api', id: event.id, kind: event.kind });
|
||||||
try {
|
try {
|
||||||
await pipeline.handleEvent(event, { source: 'api', signal: c.req.raw.signal });
|
const promise = pipeline.handleEvent(event, { source: 'api', signal: c.req.raw.signal });
|
||||||
|
|
||||||
|
promise.then(async () => {
|
||||||
const client = await Storages.client();
|
const client = await Storages.client();
|
||||||
await client.event(purifyEvent(event));
|
await client.event(purifyEvent(event));
|
||||||
|
}).catch((e: unknown) => {
|
||||||
|
logi({ level: 'error', ns: 'ditto.pool', id: event.id, kind: event.kind, error: errorJson(e) });
|
||||||
|
});
|
||||||
|
|
||||||
|
await promise;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof RelayError) {
|
if (e instanceof RelayError) {
|
||||||
throw new HTTPException(422, {
|
throw new HTTPException(422, {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue