@@ -2,8 +2,9 @@ import { logger } from "@coder/logger"
22import express from "express"
33import * as http from "http"
44import * as path from "path"
5- import { HttpCode } from "../common/http"
5+ import { HttpCode , HttpError } from "../common/http"
66import { listen } from "./app"
7+ import { errorHandler } from "./routes/errors"
78import { canConnect } from "./util"
89
910export interface EditorSessionEntry {
@@ -44,24 +45,18 @@ export async function makeEditorSessionManagerServer(
4445 async ( req , res ) => {
4546 const filePath = req . query . filePath
4647 if ( ! filePath ) {
47- res . status ( HttpCode . BadRequest ) . send ( "filePath is required" )
48- return
49- }
50- try {
51- const socketPath = await editorSessionManager . getConnectedSocketPath ( filePath )
52- const response : GetSessionResponse = { socketPath }
53- res . json ( response )
54- } catch ( error : unknown ) {
55- res . status ( HttpCode . ServerError ) . send ( error )
48+ throw new HttpError ( "filePath is required" , HttpCode . BadRequest )
5649 }
50+ const socketPath = await editorSessionManager . getConnectedSocketPath ( filePath )
51+ const response : GetSessionResponse = { socketPath }
52+ res . json ( response )
5753 } ,
5854 )
5955
6056 router . post < { } , string , AddSessionRequest | undefined > ( "/add-session" , async ( req , res ) => {
6157 const entry = req . body ?. entry
6258 if ( ! entry ) {
63- res . status ( 400 ) . send ( "entry is required" )
64- return
59+ throw new HttpError ( "entry is required" , HttpCode . BadRequest )
6560 }
6661 editorSessionManager . addSession ( entry )
6762 res . status ( 200 ) . send ( "session added" )
@@ -70,13 +65,14 @@ export async function makeEditorSessionManagerServer(
7065 router . post < { } , string , DeleteSessionRequest | undefined > ( "/delete-session" , async ( req , res ) => {
7166 const socketPath = req . body ?. socketPath
7267 if ( ! socketPath ) {
73- res . status ( 400 ) . send ( "socketPath is required" )
74- return
68+ throw new HttpError ( "socketPath is required" , HttpCode . BadRequest )
7569 }
7670 editorSessionManager . deleteSession ( socketPath )
7771 res . status ( 200 ) . send ( "session deleted" )
7872 } )
7973
74+ router . use ( errorHandler )
75+
8076 const server = http . createServer ( router )
8177 try {
8278 await listen ( server , { socket : codeServerSocketPath } )
0 commit comments