Archived
1
0

Remove unnecessary return types

This commit is contained in:
Asher 2020-03-11 16:00:39 -05:00
parent f6a5eaa965
commit 253cf1c438
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
3 changed files with 7 additions and 19 deletions

View File

@ -93,7 +93,7 @@ export class ApiHttpProvider extends HttpProvider {
request: http.IncomingMessage, request: http.IncomingMessage,
socket: net.Socket, socket: net.Socket,
head: Buffer, head: Buffer,
): Promise<true> { ): Promise<void> {
if (!this.authenticated(request)) { if (!this.authenticated(request)) {
throw new Error("not authenticated") throw new Error("not authenticated")
} }
@ -107,7 +107,7 @@ export class ApiHttpProvider extends HttpProvider {
throw new HttpError("Not found", HttpCode.NotFound) throw new HttpError("Not found", HttpCode.NotFound)
} }
private async handleStatusSocket(request: http.IncomingMessage, socket: net.Socket, head: Buffer): Promise<true> { private async handleStatusSocket(request: http.IncomingMessage, socket: net.Socket, head: Buffer): Promise<void> {
const getMessageResponse = async (event: "health"): Promise<ServerMessage> => { const getMessageResponse = async (event: "health"): Promise<ServerMessage> => {
switch (event) { switch (event) {
case "health": case "health":
@ -134,8 +134,6 @@ export class ApiHttpProvider extends HttpProvider {
resolve() resolve()
}) })
}) })
return true
} }
/** /**
@ -146,7 +144,7 @@ export class ApiHttpProvider extends HttpProvider {
request: http.IncomingMessage, request: http.IncomingMessage,
socket: net.Socket, socket: net.Socket,
head: Buffer, head: Buffer,
): Promise<true> { ): Promise<void> {
const sessionId = route.requestPath.replace(/^\//, "") const sessionId = route.requestPath.replace(/^\//, "")
logger.debug("connecting session", field("sessionId", sessionId)) logger.debug("connecting session", field("sessionId", sessionId))
const ws = await new Promise<WebSocket>((resolve, reject) => { const ws = await new Promise<WebSocket>((resolve, reject) => {
@ -177,8 +175,6 @@ export class ApiHttpProvider extends HttpProvider {
}), }),
), ),
) )
return true
} }
/** /**

View File

@ -89,7 +89,7 @@ export class VscodeHttpProvider extends HttpProvider {
return this._vscode return this._vscode
} }
public async handleWebSocket(route: Route, request: http.IncomingMessage, socket: net.Socket): Promise<true> { public async handleWebSocket(route: Route, request: http.IncomingMessage, socket: net.Socket): Promise<void> {
if (!this.authenticated(request)) { if (!this.authenticated(request)) {
throw new Error("not authenticated") throw new Error("not authenticated")
} }
@ -113,7 +113,6 @@ export class VscodeHttpProvider extends HttpProvider {
const vscode = await this._vscode const vscode = await this._vscode
this.send({ type: "socket", query: route.query }, vscode, socket) this.send({ type: "socket", query: route.query }, vscode, socket)
return true
} }
private send(message: CodeServerMessage, vscode?: cp.ChildProcess, socket?: net.Socket): void { private send(message: CodeServerMessage, vscode?: cp.ChildProcess, socket?: net.Socket): void {

View File

@ -147,14 +147,14 @@ export abstract class HttpProvider {
_socket: net.Socket, _socket: net.Socket,
_head: Buffer, _head: Buffer,
/* eslint-enable @typescript-eslint/no-unused-vars */ /* eslint-enable @typescript-eslint/no-unused-vars */
): Promise<true | undefined> { ): Promise<void> {
throw new HttpError("Not found", HttpCode.NotFound) throw new HttpError("Not found", HttpCode.NotFound)
} }
/** /**
* Handle requests to the registered endpoint. * Handle requests to the registered endpoint.
*/ */
public abstract handleRequest(route: Route, request: http.IncomingMessage): Promise<HttpResponse | undefined> public abstract handleRequest(route: Route, request: http.IncomingMessage): Promise<HttpResponse>
/** /**
* Get the base relative to the provided route. For each slash we need to go * 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) const route = this.parseUrl(request)
try { try {
const payload = this.maybeRedirect(request, route) || (await route.provider.handleRequest(route, request)) 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, { response.writeHead(payload.redirect ? HttpCode.Redirect : payload.code || HttpCode.Ok, {
"Content-Type": payload.mime || getMediaMime(payload.filePath), "Content-Type": payload.mime || getMediaMime(payload.filePath),
...(payload.redirect ? { Location: this.constructRedirect(request, route, payload as RedirectResponse) } : {}), ...(payload.redirect ? { Location: this.constructRedirect(request, route, payload as RedirectResponse) } : {}),
@ -633,11 +630,7 @@ export class HttpServer {
throw new HttpError("Not found", HttpCode.NotFound) throw new HttpError("Not found", HttpCode.NotFound)
} }
if ( await route.provider.handleWebSocket(route, request, await this.socketProvider.createProxy(socket), head)
!(await route.provider.handleWebSocket(route, request, await this.socketProvider.createProxy(socket), head))
) {
throw new HttpError("Not found", HttpCode.NotFound)
}
} catch (error) { } catch (error) {
socket.destroy(error) socket.destroy(error)
logger.warn(`discarding socket connection: ${error.message}`) logger.warn(`discarding socket connection: ${error.message}`)