Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/lib/redis/dead-letter-queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Dead letter queue for failed events (frontend hook-point).
*
* Minimal DLQ over the existing Redis client. Retry/manual-requeue logic
* lives in the backend jobqueue.
*/

import { getRedisClient } from "../redis/client"

const DLQ_KEY = "moistello:dlq"

export interface DeadLetterEvent {
id: string
type: string
attempts: number
error: string
}

export class DeadLetterQueue {
async push(event: DeadLetterEvent): Promise<void> {
await getRedisClient().rpush(DLQ_KEY, JSON.stringify(event))
}

async list(): Promise<DeadLetterEvent[]> {
const raw = await getRedisClient().lrange(DLQ_KEY, 0, -1)
return raw.map((item) => JSON.parse(item) as DeadLetterEvent)
}

async retry(id: string): Promise<void> {
await getRedisClient().lrem(DLQ_KEY, 0, JSON.stringify({ id }))
}
}
33 changes: 33 additions & 0 deletions src/lib/stellar/error-classifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Soroban error classification (frontend hook-point).
*
* Maps Soroban/Stellar error responses to typed domain errors. The
* authoritative classifier (Go) lives in pkg/stellar/errors.go in the
* backend; this mirrors the same codes for client-side handling.
*/

export class SorobanError extends Error {
code: string
isRetryable: boolean

constructor(code: string, message: string, isRetryable: boolean) {
super(message)
this.code = code
this.isRetryable = isRetryable
}
}

export function classifySorobanError(
statusCode: number,
body: string,
): SorobanError {
const message = body.trim()
switch (statusCode) {
case 429:
return new SorobanError("TX_RATE_LIMITED", message, true)
case 400:
return new SorobanError("TX_BAD_REQUEST", message, false)
default:
return new SorobanError("TX_UNKNOWN", message, false)
}
}