microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4cd259621ddfbd348fade892a2f3ee87fd1924c5

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/common/node/request.ts

28lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import http = require("http");
5import https = require("https");
6
7export class Request {
8 public static request(url: string, expectStatusOK = false, isHttps = false): Promise<string> {
9 return new Promise((resolve, reject) => {
10 let req = (isHttps ? https : http).get(url, function (res) {
11 let responseString = "";
12 res.on("data", (data: Buffer) => {
13 responseString += data.toString();
14 });
15 res.on("end", () => {
16 if (expectStatusOK && res.statusCode !== 200) {
17 reject(new Error(responseString));
18 } else {
19 resolve(responseString);
20 }
21 });
22 });
23 req.on("error", (err: Error) => {
24 reject(err);
25 });
26 });
27 }
28}
29