lib/client/sarahClient.js   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 38
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 38
rs 10
wmc 3
mnd 0
bc 3
fnc 3
bpm 1
cpm 1
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A sarahClient.js ➔ ??? 0 17 1
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)}`);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
34
        })
35
        .catch(error => {
36
            return Promise.reject(new NestedError('sarahClient error', error));
37
        });
38
};
39