avem
avem
HHono
Created by avem on 10/14/2024 in #help
Pass context to exception handler
I guess the only way of doing it is to wrap exception and add context? I would like to avoid that since, some of the libraries I use throw exceptions in uncaught promises, which don't allow me to catch them in handler try/catch block.
4 replies
HHono
Created by avem on 10/14/2024 in #help
Pass context to exception handler
// Example route
app.get('/', async (c) => {
// ....computing the context...
const context = {
extensionID: params.extension_id,
fingerprint: params.fingerprint,
plan: account.plan(),
accountID: account.id(),
extensionVersion: params.extension_version,
currentPhoto: account.totalUsage() + 1,
clerkID: clerkID,
aiMode: params.ai_mode,
solveMode: params.solve_mode,
language: params.language,
joinedAt: account.createdAt(),
};

// ...some exception happening..
});

// Custom error handler
app.onError((err, c) => {
// I want to have access to it in here via "c"
});
// Example route
app.get('/', async (c) => {
// ....computing the context...
const context = {
extensionID: params.extension_id,
fingerprint: params.fingerprint,
plan: account.plan(),
accountID: account.id(),
extensionVersion: params.extension_version,
currentPhoto: account.totalUsage() + 1,
clerkID: clerkID,
aiMode: params.ai_mode,
solveMode: params.solve_mode,
language: params.language,
joinedAt: account.createdAt(),
};

// ...some exception happening..
});

// Custom error handler
app.onError((err, c) => {
// I want to have access to it in here via "c"
});
4 replies