mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Move errorHandler to a separate file
This commit is contained in:
parent
8923a5ee55
commit
d4713cae01
2 changed files with 13 additions and 6 deletions
|
|
@ -108,6 +108,7 @@ import {
|
|||
trendingStatusesController,
|
||||
trendingTagsController,
|
||||
} from '@/controllers/api/trends.ts';
|
||||
import { errorHandler } from '@/controllers/error.ts';
|
||||
import { metricsController } from '@/controllers/metrics.ts';
|
||||
import { indexController } from '@/controllers/site.ts';
|
||||
import { nodeInfoController, nodeInfoSchemaController } from '@/controllers/well-known/nodeinfo.ts';
|
||||
|
|
@ -340,12 +341,7 @@ app.get('/', frontendController, indexController);
|
|||
// Fallback
|
||||
app.get('*', publicFiles, staticFiles, frontendController);
|
||||
|
||||
app.onError((err, c) => {
|
||||
if (err.message === 'canceling statement due to statement timeout') {
|
||||
return c.json({ error: 'The server was unable to respond in a timely manner' }, 500);
|
||||
}
|
||||
return c.json({ error: 'Something went wrong' }, 500);
|
||||
});
|
||||
app.onError(errorHandler);
|
||||
|
||||
export default app;
|
||||
|
||||
|
|
|
|||
11
src/controllers/error.ts
Normal file
11
src/controllers/error.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { ErrorHandler } from '@hono/hono';
|
||||
|
||||
export const errorHandler: ErrorHandler = (err, c) => {
|
||||
console.error(err);
|
||||
|
||||
if (err.message === 'canceling statement due to statement timeout') {
|
||||
return c.json({ error: 'The server was unable to respond in a timely manner' }, 500);
|
||||
}
|
||||
|
||||
return c.json({ error: 'Something went wrong' }, 500);
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue