Skip to content

Commit 552d8c1

Browse files
committed
Merge pull request #7 from GODDET/patch-1
Add rejectUnauthorized as an option and fix error message when "response" is null
2 parents 4c0cfe7 + a5c7e46 commit 552d8c1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tasks/http_upload.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = function(grunt) {
2020

2121
// Merge task-specific and/or target-specific options with these defaults.
2222
var options = this.options({
23+
rejectUnauthorized: true,
2324
method: 'POST',
2425
headers: {},
2526
url: ''
@@ -52,15 +53,18 @@ module.exports = function(grunt) {
5253
reqData[field] = rest.file(filepath, null, fileSize, null, null);
5354
// HTTP request
5455
rest.request(options.url, {
56+
rejectUnauthorized: options.rejectUnauthorized,
5557
method: options.method,
5658
headers: options.headers,
5759
multipart: true,
5860
data: reqData
5961
}).on('complete', function(data, response) {
60-
if (response.statusCode >= 200 && response.statusCode < 300) {
62+
if (response !== null && response.statusCode >= 200 && response.statusCode < 300) {
6163
grunt.log.ok('Upload successful of "' + filepath + '" as "' + field + '" - ' + options.method + ' @ ' + options.url);
64+
} else if (response !== null) {
65+
grunt.fail.warn('Failed uploading "' + filepath + '" as "' + field + '" (status code: ' + response.statusCode + ') - ' + options.method + ' @ ' + options.url);
6266
} else {
63-
grunt.fail.warn('Failed uploading "' + filepath + '" as "' + field + '" (status code: ' + response.statusCode + ') - ' + options.method + ' @ ' + options.url);
67+
grunt.fail.warn('Failed uploading "' + filepath + '" as "' + field + '" (status code: null) - ' + options.method + ' @ ' + options.url);
6468
}
6569
// callback once upload is done
6670
done(data);

0 commit comments

Comments
 (0)