Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Update Node types and TypeScript #114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,21 +525,18 @@ export class ServiceClient {
constructor(optionsOrUrl: ServiceClientOptions | string) {
let options: ServiceClientOptions;
if (typeof optionsOrUrl === "string") {
const {
port,
protocol,
query,
hostname = "",
pathname = "/"
} = url.parse(optionsOrUrl, true);
const { port, protocol, query, hostname, pathname } = url.parse(
optionsOrUrl,
true
);
options = {
hostname,
hostname: hostname || "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hostname: hostname || "",
hostname: hostname ?? "",

defaultRequestOptions: {
port,
protocol,
query,
// pathname will be overwritten in actual usage, we just guarantee a sane default
pathname
Comment on lines -528 to -542

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any issue with the defaults not working with deconstruction?

pathname: pathname || "/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pathname: pathname || "/"
pathname: pathname ?? "/"

}
};
} else {
Expand Down
7 changes: 5 additions & 2 deletions lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as zlib from "zlib";
import { ServiceClientError } from "./client";
import { Socket } from "net";
import { Readable } from "stream";
import { ParsedUrlQueryInput } from "querystring";

const DEFAULT_READ_TIMEOUT = 2000;
const DEFAULT_CONNECTION_TIMEOUT = 1000;
Expand Down Expand Up @@ -53,7 +54,7 @@ interface Span {

export interface ServiceClientRequestOptions extends RequestOptions {
pathname: string;
query?: object;
query?: ParsedUrlQueryInput;
timing?: boolean;
autoDecodeUtf8?: boolean;
dropRequestAfter?: number;
Expand Down Expand Up @@ -234,7 +235,9 @@ export const request = (
const requestObject = httpRequestFn(options);
requestObject.setTimeout(readTimeout, () => {
logEvent(EventSource.HTTP_REQUEST, EventName.TIMEOUT);
requestObject.socket.destroy();
if (requestObject.socket != null) {
requestObject.socket.destroy();
}
Comment on lines +238 to +240
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (requestObject.socket != null) {
requestObject.socket.destroy();
}
requestObject.socket?.destroy();

reject(new ReadTimeoutError(options));
});

Expand Down
Loading