mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-25 23:54:37 +02:00
Extract the credit system from mana-core-auth into a standalone service. Uses Hono framework on Bun runtime instead of NestJS. Service includes: - Personal credit balance with optimistic locking - Immutable transaction ledger - Stripe payment integration (PaymentIntents, Checkout Sessions) - Guild shared pools with per-member spending limits - Gift code system (simple, personalized, split, first_come, riddle) - Service-to-service internal API (X-Service-Key auth) - JWT validation via JWKS from mana-core-auth (jose library) Architecture: - 27 files, ~2.2k LOC (vs ~4.1k in NestJS) - Drizzle ORM schemas adapted for standalone DB (no FK to auth tables) - Zod validation instead of class-validator - Manual service instantiation instead of NestJS DI - Hono middleware for JWT + service key auth Port: 3060 Database: mana_credits (separate from mana_auth) Next steps: Update CreditClientService URL, update mana-core-auth registration hooks, configure Docker + Cloudflare Tunnel. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
29 lines
592 B
TypeScript
29 lines
592 B
TypeScript
/**
|
|
* Global error handler middleware for Hono.
|
|
*/
|
|
|
|
import type { ErrorHandler } from 'hono';
|
|
import { HTTPException } from 'hono/http-exception';
|
|
|
|
export const errorHandler: ErrorHandler = (err, c) => {
|
|
if (err instanceof HTTPException) {
|
|
const cause = err.cause as Record<string, unknown> | undefined;
|
|
return c.json(
|
|
{
|
|
statusCode: err.status,
|
|
message: err.message,
|
|
...(cause ? { details: cause } : {}),
|
|
},
|
|
err.status
|
|
);
|
|
}
|
|
|
|
console.error('Unhandled error:', err);
|
|
return c.json(
|
|
{
|
|
statusCode: 500,
|
|
message: 'Internal server error',
|
|
},
|
|
500
|
|
);
|
|
};
|