Total Complexity | 3 |
Complexity/F | 1 |
Lines of Code | 38 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | "use strict"; |
||
2 | |||
3 | const config = require('config').sarah.client; |
||
4 | const NestedError = require('nested-error-stacks'); |
||
5 | const request = require('request-promise-native'); |
||
6 | |||
7 | const defaultOptionList = { |
||
8 | uri: `${config.scheme}://${config.host}:${config.port}`, |
||
9 | headers: {'User-Agent': 'Alfred-server'}, |
||
10 | qs: {}, // <-- to override before call |
||
11 | json: true, |
||
12 | simple: true, |
||
13 | resolveWithFullResponse: true |
||
14 | }; |
||
15 | |||
16 | /** |
||
17 | * @param {Object} attributeList |
||
18 | * @param {string} httpMethod |
||
19 | * |
||
20 | * @returns {Promise<null|Error>} |
||
21 | */ |
||
22 | module.exports = (attributeList, httpMethod = 'GET') => { |
||
23 | // Append queryString to default options |
||
24 | const optionList = Object.assign( |
||
25 | defaultOptionList, |
||
26 | { |
||
27 | method: httpMethod, |
||
28 | qs: attributeList |
||
29 | }); |
||
30 | |||
31 | return request(optionList) |
||
32 | .then(data => { |
||
33 | console.log(`data ${JSON.stringify(data)}`); |
||
|
|||
34 | }) |
||
35 | .catch(error => { |
||
36 | return Promise.reject(new NestedError('sarahClient error', error)); |
||
37 | }); |
||
38 | }; |
||
39 |