fix build
This commit is contained in:
parent
ea13843960
commit
b24915783d
|
|
@ -1 +1 @@
|
||||||
1.1.47
|
1.1.49
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
import type { Context, Env } from 'hono';
|
import type { Context } from 'hono';
|
||||||
|
|
||||||
type Handler<E extends Env> = (c: Context<E>) => Promise<Response>;
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
type AnyHandler = (c: Context<any>) => Promise<any>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps a route handler with structured error logging.
|
* Wraps a route handler with structured error logging.
|
||||||
* Logs the route label, error message and stack, then returns 500.
|
* Preserves the handler's generic type so Hono can infer env/input/output types correctly.
|
||||||
*/
|
*/
|
||||||
export function handle<E extends Env>(label: string, fn: Handler<E>): Handler<E> {
|
export function handle<F extends AnyHandler>(label: string, fn: F): F {
|
||||||
return async (c: Context<E>) => {
|
return (async (c: Context<any>) => {
|
||||||
try {
|
try {
|
||||||
return await fn(c);
|
return await fn(c);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -16,5 +17,5 @@ export function handle<E extends Env>(label: string, fn: Handler<E>): Handler<E>
|
||||||
console.error(`[${label}]`, c.req.method, c.req.path, msg, stack);
|
console.error(`[${label}]`, c.req.method, c.req.path, msg, stack);
|
||||||
return c.json({ error: 'internal server error', detail: msg }, 500);
|
return c.json({ error: 'internal server error', detail: msg }, 500);
|
||||||
}
|
}
|
||||||
};
|
}) as F;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,8 @@ const pushDailyLogRoute = createRoute({
|
||||||
|
|
||||||
const push = new OpenAPIHono<AuthEnv>();
|
const push = new OpenAPIHono<AuthEnv>();
|
||||||
|
|
||||||
push.openapi(pushDailyLogRoute, handle('push/daily-log', async (c) => {
|
push.openapi(pushDailyLogRoute, async (c) => {
|
||||||
|
try {
|
||||||
const { userId } = c.get('auth');
|
const { userId } = c.get('auth');
|
||||||
|
|
||||||
const lock = await isLocked(userId);
|
const lock = await isLocked(userId);
|
||||||
|
|
@ -143,6 +144,12 @@ push.openapi(pushDailyLogRoute, handle('push/daily-log', async (c) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
return c.json({ contextId: 'daily-log', topicId: JOURNAL_TOPIC_ID, historyEntryId: id }, 201);
|
return c.json({ contextId: 'daily-log', topicId: JOURNAL_TOPIC_ID, historyEntryId: id }, 201);
|
||||||
}));
|
} catch (err) {
|
||||||
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
|
console.error('[push/daily-log]', msg);
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
return c.json({ error: 'internal server error', detail: msg }, 500) as any;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default push;
|
export default push;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue