fix: closure compiler requires HTTPS now (#2007)

Also barfing out the response from the server when JSON parsing errors happen
This commit is contained in:
Pat Cavit 2017-10-28 22:57:52 -07:00 committed by GitHub
parent 3c608f26b7
commit efb0e94d99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
"use strict"
var http = require("http")
var http = require("https")
var querystring = require("querystring")
var fs = require("fs")
@ -22,7 +22,6 @@ module.exports = function(input, output, options, done) {
var response = ""
var req = http.request({
method: "POST",
protocol: "http:",
hostname: "closure-compiler.appspot.com",
path: "/compile",
headers: {
@ -33,8 +32,16 @@ module.exports = function(input, output, options, done) {
res.on("data", function(chunk) {
response += chunk.toString()
})
res.on("end", function() {
var results = JSON.parse(response)
try {
var results = JSON.parse(response)
} catch(e) {
console.error(response);
throw e;
}
if (results.errors) {
for (var i = 0; i < results.errors.length; i++) console.log(results.errors[i])
}