From 253cf1c43861b6e673b0b39b12824cc98a87c54f Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 11 Mar 2020 16:00:39 -0500 Subject: [PATCH] Remove unnecessary return types --- src/node/app/api.ts | 10 +++------- src/node/app/vscode.ts | 3 +-- src/node/http.ts | 13 +++---------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/node/app/api.ts b/src/node/app/api.ts index 6615df1e..98424c02 100644 --- a/src/node/app/api.ts +++ b/src/node/app/api.ts @@ -93,7 +93,7 @@ export class ApiHttpProvider extends HttpProvider { request: http.IncomingMessage, socket: net.Socket, head: Buffer, - ): Promise { + ): Promise { if (!this.authenticated(request)) { throw new Error("not authenticated") } @@ -107,7 +107,7 @@ export class ApiHttpProvider extends HttpProvider { throw new HttpError("Not found", HttpCode.NotFound) } - private async handleStatusSocket(request: http.IncomingMessage, socket: net.Socket, head: Buffer): Promise { + private async handleStatusSocket(request: http.IncomingMessage, socket: net.Socket, head: Buffer): Promise { const getMessageResponse = async (event: "health"): Promise => { switch (event) { case "health": @@ -134,8 +134,6 @@ export class ApiHttpProvider extends HttpProvider { resolve() }) }) - - return true } /** @@ -146,7 +144,7 @@ export class ApiHttpProvider extends HttpProvider { request: http.IncomingMessage, socket: net.Socket, head: Buffer, - ): Promise { + ): Promise { const sessionId = route.requestPath.replace(/^\//, "") logger.debug("connecting session", field("sessionId", sessionId)) const ws = await new Promise((resolve, reject) => { @@ -177,8 +175,6 @@ export class ApiHttpProvider extends HttpProvider { }), ), ) - - return true } /** diff --git a/src/node/app/vscode.ts b/src/node/app/vscode.ts index e850c7cb..29e5c48e 100644 --- a/src/node/app/vscode.ts +++ b/src/node/app/vscode.ts @@ -89,7 +89,7 @@ export class VscodeHttpProvider extends HttpProvider { return this._vscode } - public async handleWebSocket(route: Route, request: http.IncomingMessage, socket: net.Socket): Promise { + public async handleWebSocket(route: Route, request: http.IncomingMessage, socket: net.Socket): Promise { if (!this.authenticated(request)) { throw new Error("not authenticated") } @@ -113,7 +113,6 @@ export class VscodeHttpProvider extends HttpProvider { const vscode = await this._vscode this.send({ type: "socket", query: route.query }, vscode, socket) - return true } private send(message: CodeServerMessage, vscode?: cp.ChildProcess, socket?: net.Socket): void { diff --git a/src/node/http.ts b/src/node/http.ts index adaa7a2b..a2a5e828 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -147,14 +147,14 @@ export abstract class HttpProvider { _socket: net.Socket, _head: Buffer, /* eslint-enable @typescript-eslint/no-unused-vars */ - ): Promise { + ): Promise { throw new HttpError("Not found", HttpCode.NotFound) } /** * Handle requests to the registered endpoint. */ - public abstract handleRequest(route: Route, request: http.IncomingMessage): Promise + public abstract handleRequest(route: Route, request: http.IncomingMessage): Promise /** * Get the base relative to the provided route. For each slash we need to go @@ -529,9 +529,6 @@ export class HttpServer { const route = this.parseUrl(request) try { const payload = this.maybeRedirect(request, route) || (await route.provider.handleRequest(route, request)) - if (!payload) { - throw new HttpError("Not found", HttpCode.NotFound) - } response.writeHead(payload.redirect ? HttpCode.Redirect : payload.code || HttpCode.Ok, { "Content-Type": payload.mime || getMediaMime(payload.filePath), ...(payload.redirect ? { Location: this.constructRedirect(request, route, payload as RedirectResponse) } : {}), @@ -633,11 +630,7 @@ export class HttpServer { throw new HttpError("Not found", HttpCode.NotFound) } - if ( - !(await route.provider.handleWebSocket(route, request, await this.socketProvider.createProxy(socket), head)) - ) { - throw new HttpError("Not found", HttpCode.NotFound) - } + await route.provider.handleWebSocket(route, request, await this.socketProvider.createProxy(socket), head) } catch (error) { socket.destroy(error) logger.warn(`discarding socket connection: ${error.message}`)