Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
d2664789
Commit
d2664789
authored
May 05, 2015
by
Michael Mifsud
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #909 from saper/fix/httperr
Improve binary file download error handling
parents
1bf73b59
988d4e25
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
install.js
scripts/install.js
+20
-13
No files found.
scripts/install.js
View file @
d2664789
...
...
@@ -21,11 +21,14 @@ require('../lib/extensions');
*/
function
download
(
url
,
dest
,
cb
)
{
var
returnError
=
function
(
err
)
{
cb
(
typeof
err
.
message
===
'string'
?
err
.
message
:
err
);
var
reportError
=
function
(
err
)
{
cb
([
'Cannot download "'
,
url
,
'": '
,
typeof
err
.
message
===
'string'
?
err
.
message
:
err
].
join
(
''
));
};
var
successful
=
function
(
response
)
{
return
response
.
statusCode
>=
200
&&
response
.
statusCode
<
300
;
};
if
(
url
)
{
applyProxy
({
rejectUnauthorized
:
false
},
function
(
options
)
{
options
.
headers
=
{
'User-Agent'
:
[
...
...
@@ -33,20 +36,24 @@ function download(url, dest, cb) {
'node-sass-installer/'
,
package
.
version
].
join
(
''
)
};
request
.
get
(
url
,
options
).
on
(
'response'
,
function
(
response
)
{
if
(
response
.
statusCode
<
200
||
response
.
statusCode
>=
300
)
{
returnError
([
'Can not download file from:'
,
url
].
join
());
return
;
try
{
request
(
url
,
options
,
function
(
err
,
response
)
{
if
(
err
)
{
reportError
(
err
);
}
else
if
(
!
successful
(
response
))
{
reportError
([
'HTTP error'
,
response
.
statusCode
,
response
.
statusMessage
].
join
(
' '
));
}
else
{
cb
();
}
}).
on
(
'response'
,
function
(
response
)
{
if
(
successful
(
response
))
{
response
.
pipe
(
fs
.
createWriteStream
(
dest
));
cb
();
}).
on
(
'error'
,
returnError
);
}
});
}
else
{
returnError
(
'Download URL not defined, set SASS_BINARY_SITE in the environment to enable download.'
);
}
catch
(
err
)
{
cb
(
err
);
}
});
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment