Browse Source

workaround throwing in promise mode

Fixes #99
http2
Vsevolod Strukchinsky 9 years ago
parent
commit
0109725b74
  1. 10
      index.js
  2. 9
      test/test-arguments.js
  3. 9
      test/test-error.js

10
index.js

@ -256,14 +256,16 @@ function got(url, opts, cb) {
opts = {};
}
opts = normalizeArguments(url, opts);
if (cb) {
asCallback(opts, cb);
asCallback(normalizeArguments(url, opts), cb);
return null;
}
return asPromise(opts);
try {
return asPromise(normalizeArguments(url, opts));
} catch (error) {
return PinkiePromise.reject(error);
}
}
var helpers = [

9
test/test-arguments.js

@ -24,10 +24,15 @@ test('setup', function (t) {
});
test('url argument is required', function (t) {
t.plan(2);
t.throws(function () {
got();
got(undefined, function () {});
}, /Parameter `url` must be a string or object, not undefined/);
t.end();
got()
.catch(function (err) {
t.ok(/Parameter `url` must be a string or object, not undefined/.test(err.message));
});
});
test('accepts url.parse object as first argument', function (t) {

9
test/test-error.js

@ -36,10 +36,15 @@ test('dns error message', function (t) {
});
test('options.body error message', function (t) {
t.plan(2);
t.throws(function () {
got(s.url, {body: function () {}});
got(s.url, {body: function () {}}, function () {});
}, /options.body must be a ReadableStream, string, Buffer or plain Object/);
t.end();
got(s.url, {body: function () {}})
.catch(function (err) {
t.ok(/options.body must be a ReadableStream, string, Buffer or plain Object/.test(err.message));
});
});
test('cleanup', function (t) {

Loading…
Cancel
Save