summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-06-23 09:02:32 +0200
committerRory& <root@rory.gay>2026-06-23 09:02:32 +0200
commit234403f7d5781ed7681dd50a8585bb7c5ccda857 (patch)
treed45e8dbfd517cce7fa414fc0078b2a76058d8720
parentOp14: always query sessions... (diff)
downloadserver-ts-234403f7d5781ed7681dd50a8585bb7c5ccda857.tar.xz
Gateway offload: gracefully fall back to TS code on failure
-rw-r--r--src/gateway/opcodes/GuildSync.ts2
-rw-r--r--src/gateway/opcodes/LazyRequest.ts2
-rw-r--r--src/gateway/opcodes/RequestChannelInfo.ts2
-rw-r--r--src/gateway/opcodes/RequestChannelStatuses.ts2
-rw-r--r--src/gateway/opcodes/RequestGuildMembers.ts2
-rw-r--r--src/gateway/util/Utils.ts7
6 files changed, 10 insertions, 7 deletions
diff --git a/src/gateway/opcodes/GuildSync.ts b/src/gateway/opcodes/GuildSync.ts

index f7c0dd0c..ce7ea773 100644 --- a/src/gateway/opcodes/GuildSync.ts +++ b/src/gateway/opcodes/GuildSync.ts
@@ -32,7 +32,7 @@ export async function onGuildSync(this: WebSocket, { d }: Payload) { if (!Array.isArray(d)) throw new Error("Invalid payload for GUILD_SYNC"); if (Config.get().offload.gateway.guildSyncUrl !== null) { - return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.guildSyncUrl!, d); + if (await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.guildSyncUrl!, d)) return; } const guild_ids = d as string[]; diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts
index 410c265f..342401b4 100644 --- a/src/gateway/opcodes/LazyRequest.ts +++ b/src/gateway/opcodes/LazyRequest.ts
@@ -159,7 +159,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) { const { guild_id, typing, channels, activities, members } = d as LazyRequestSchema; if (Config.get().offload.gateway.lazyRequestUrl !== null) { - return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.lazyRequestUrl!, d); + if (await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.lazyRequestUrl!, d)) return; } if (members) { diff --git a/src/gateway/opcodes/RequestChannelInfo.ts b/src/gateway/opcodes/RequestChannelInfo.ts
index 8cb9098d..7ef91df2 100644 --- a/src/gateway/opcodes/RequestChannelInfo.ts +++ b/src/gateway/opcodes/RequestChannelInfo.ts
@@ -27,7 +27,7 @@ export async function onRequestChannelInfo(this: WebSocket, { d }: Payload) { if (!d.fields) throw new Error('"fields" is required'); if (Config.get().offload.gateway.channelInfoUrl !== null) { - return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.channelInfoUrl!, d); + if (await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.channelInfoUrl!, d)) return; } const channels = ( diff --git a/src/gateway/opcodes/RequestChannelStatuses.ts b/src/gateway/opcodes/RequestChannelStatuses.ts
index 1747faae..b0b291e7 100644 --- a/src/gateway/opcodes/RequestChannelStatuses.ts +++ b/src/gateway/opcodes/RequestChannelStatuses.ts
@@ -24,7 +24,7 @@ export async function onRequestChannelStatuses(this: WebSocket, { d }: Payload) if (!d.guild_id) throw new Error('"guild_id" is required'); if (Config.get().offload.gateway.channelStatusesUrl !== null) { - return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.channelStatusesUrl!, d); + if (await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.channelStatusesUrl!, d)) return; } // TODO: implement diff --git a/src/gateway/opcodes/RequestGuildMembers.ts b/src/gateway/opcodes/RequestGuildMembers.ts
index db13ea8c..ab7f516d 100644 --- a/src/gateway/opcodes/RequestGuildMembers.ts +++ b/src/gateway/opcodes/RequestGuildMembers.ts
@@ -34,7 +34,7 @@ export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) { if (Config.get().offload.gateway.guildMembersUrl !== null) { const guildIds: string[] = Array.isArray(d.guild_id) ? d.guild_id : [d.guild_id]; - return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.guildMembersUrl!, guildIds); + if (await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.guildMembersUrl!, guildIds)) return; } check.call(this, RequestGuildMembersSchema, d); diff --git a/src/gateway/util/Utils.ts b/src/gateway/util/Utils.ts
index bbb05436..adc7bbec 100644 --- a/src/gateway/util/Utils.ts +++ b/src/gateway/util/Utils.ts
@@ -97,7 +97,7 @@ async function expireOldPresenceStates() { } } -export async function handleOffloadedGatewayRequest(socket: WebSocket, url: string, body: unknown) { +export async function handleOffloadedGatewayRequest(socket: WebSocket, url: string, body: unknown): Promise<boolean> { // TODO: async json object streaming const resp = await fetch(url, { body: JSON.stringify(body), @@ -114,7 +114,8 @@ export async function handleOffloadedGatewayRequest(socket: WebSocket, url: stri const text = await resp.text(); console.error(`[Gateway] Offloaded request to ${url} failed with status ${resp.status}: ${text}`); if (resp.status === 415 || resp.status === 400) console.log(typeof body, body); - throw new Error(`Offloaded request failed with status ${resp.status}: ${text}`); + // throw new Error(`Offloaded request failed with status ${resp.status}: ${text}`); + return false; } const data = ((await resp.json()) as Event[]).toReversed(); @@ -128,4 +129,6 @@ export async function handleOffloadedGatewayRequest(socket: WebSocket, url: stri d: event.data, }); } + + return true; }