refactor: improve error handling with global router catchall

This commit is contained in:
Nicolas Meienberger
2025-09-24 17:44:41 +02:00
parent db88bb6de2
commit 677db2f90f
16 changed files with 321 additions and 361 deletions

View File

@@ -8,6 +8,7 @@ import { driverController } from "./modules/driver/driver.controller";
import { volumeController } from "./modules/volumes/volume.controller";
import { logger } from "./utils/logger";
import { startup } from "./modules/lifecycle/startup";
import { handleServiceError } from "./utils/errors";
export const generalDescriptor = (app: Hono) =>
openAPISpecs(app, {
@@ -41,6 +42,18 @@ app.get("/", (c) => {
return c.json({ message: "Welcome to the Ironmount API" });
});
app.onError((err, c) => {
logger.error(`${c.req.url}: ${err.message}`);
if (err.cause instanceof Error) {
logger.error(err.cause.message);
}
const { status, message } = handleServiceError(err);
return c.json({ error: message }, status);
});
const socketPath = "/run/docker/plugins/ironmount.sock";
(async () => {