getAd(callback) { rp(url) .then(function(result) { callback(result) }) .catch(function(err) { callback("err") }); }
function hasOpenWebHook(port, reverse) { assert.ok(port); const error = new Error('open-webhook-check failed'); let connected = false; return request.get(`http://127.0.0.1:${port}`) .then(() => { connected = true; }).catch(e => { if (e.statusCode < 500) connected = true; }).finally(() => { if (reverse) { if (connected) throw error; return; } if (!connected) throw error; }); }
describe('WebHook', function webHookSuite() { it('returns 200 OK for health endpoint', function test(done) { utils.sendWebHookRequest(webHookPort2, '/healthz').then(resp => { assert.equal(resp, 'OK'); return done(); }); }); it('returns 401 error if token is wrong', function test(done) { utils.sendWebHookMessage(webHookPort2, 'wrong-token').catch(resp => { assert.equal(resp.statusCode, 401); return done(); }); }); it('only accepts POST method', function test() { const methods = ['GET', 'PUT', 'DELETE', 'OPTIONS']; return Promise.each(methods, (method) => { return utils.sendWebHookMessage(webHookPort2, TOKEN, { method, }).then(() => { throw new Error(`expected error with webhook ${method} request`); }).catch(resp => { if (!resp.statusCode) throw resp; if (resp.statusCode !== 418) throw new Error(`unexpected error: ${resp.body}`); }); }); // Promise.each }); });
.then(async content => { const body = processReadme(content, { source: url });
debug('HTTP request: %j', options); return request(options) .then(resp => { let data; try {
r.then(function (data) { configstore.set('latest.version', data.version); configstore.set('latest.fetched', Date.now()); init(data); });
describe('lib/fetch', () => { test('return a promise', () => { expect.assertions(1); return fetch('https://jsonplaceholder.typicode.com/todos/1').then(res => { const { id } = JSON.parse(res); expect(id).toBe(1); }); }); });
request(options).then( res=>{ debug("alipay query trade , return data ",res) var response = JSON.parse(res) if (!this.verify_sync(response.alipay_trade_query_response,response.sign)){ return Promise.reject('Sign verification failed for alipay notification'); } return Promise.resolve(response); })
request.post(`http://${this.hostname}:${this.port}/json_rpc`, options) .then((result) => { if (result.hasOwnProperty('result')) { return result.result; } else { return result; } })
function getMovieDetail(href, res, next) { rq(href).then(str => { const $ = cheerio.load(str) const data = fillData($) res.json({ code: CONFIG.ERR_OK, data }) }) }
screenshot () { return rp(`${config.url}/screenshot`) .then((data) => { return JSON.parse(data)['value'] }) .catch(() => { console.log('截图失败') }) }
// const pageNum = req.query.page; // const start = pageNum ? (pageNum - 1) * 20 : 0; rp(`${ECHO_API}/tracks/${id}`) .then((resp) => res.send(resp)) .catch((err) => next(err));
rp(options).then(function (data) { return data.ID; }).catch(function (err) { debuglog('createConsulToken failed: ', err); return null; })