refactor: restructure error handling
This commit is contained in:
parent
a6f457ef59
commit
2eb2388e12
@ -107,18 +107,14 @@ io.on("connection", async (socket) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const sandboxManager = sandboxManagers[data.sandboxId] ?? new SandboxManager(
|
const sandboxManager = sandboxManagers[data.sandboxId] ?? new SandboxManager(
|
||||||
data.sandboxId,
|
data.sandboxId,
|
||||||
data.userId,
|
data.userId,
|
||||||
{ aiWorker, dokkuClient, gitClient, socket }
|
{ aiWorker, dokkuClient, gitClient, socket }
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
|
||||||
sandboxManager.initializeContainer()
|
sandboxManager.initializeContainer()
|
||||||
} catch (e: any) {
|
|
||||||
console.error(`Error initializing sandbox ${data.sandboxId}:`, e);
|
|
||||||
socket.emit("error", `Error: initialize sandbox ${data.sandboxId}. ${e.message ?? e}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.entries(sandboxManager.handlers()).forEach(([event, handler]) => {
|
Object.entries(sandboxManager.handlers()).forEach(([event, handler]) => {
|
||||||
socket.on(event, async (options: any, callback?: (response: any) => void) => {
|
socket.on(event, async (options: any, callback?: (response: any) => void) => {
|
||||||
@ -151,6 +147,12 @@ io.on("connection", async (socket) => {
|
|||||||
socket.emit("error", `Error: disconnecting. ${e.message ?? e}`)
|
socket.emit("error", `Error: disconnecting. ${e.message ?? e}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error(`Error initializing sandbox ${data.sandboxId}:`, e);
|
||||||
|
socket.emit("error", `Error: initialize sandbox ${data.sandboxId}. ${e.message ?? e}`);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error("Error connecting:", e)
|
console.error("Error connecting:", e)
|
||||||
socket.emit("error", `Error: connection. ${e.message ?? e}`)
|
socket.emit("error", `Error: connection. ${e.message ?? e}`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user