Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 36 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /** |
||
22 | let name = `success`; |
||
23 | |||
24 | /** |
||
25 | * Attempt to parse the body of a successful request to Codingame test API. |
||
26 | * This function will try to map a response for a successful test. |
||
27 | * |
||
28 | * @function parse |
||
29 | * @param {Object} body Body of the response |
||
30 | * @returns {Promise<string>} Resolve with the successful result value |
||
31 | * @throws {Error} Throw is parsing failed |
||
32 | * @instance |
||
33 | */ |
||
34 | let parse = (body) => { |
||
35 | try { |
||
36 | let { |
||
37 | "output": output, |
||
38 | "comparison": { |
||
39 | "success": success |
||
40 | } |
||
41 | } = body; |
||
42 | if (success) { |
||
|
|||
43 | return Promise.resolve(output); |
||
44 | } else { |
||
45 | throw `Success property must be true`; |
||
46 | } |
||
47 | } catch(error) { |
||
48 | let message = `The body is not of response type '${name}'\n`; |
||
49 | message += error.message; |
||
50 | throw new Error(message); |
||
51 | } |
||
52 | }; |
||
53 | |||
54 | export default { |
||
55 | "name": name, |
||
56 | "parse": parse |
||
57 | }; |
||
58 |