Total Complexity | 4 |
Complexity/F | 4 |
Lines of Code | 43 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /** |
||
26 | import CodingameError from '../error.js'; |
||
27 | |||
28 | let name = `fail-compile`; |
||
29 | |||
30 | /** |
||
31 | * Attempt to parse the body of a successful request to Codingame test API. |
||
32 | * This function will try to map a response for a failed test because the compilation of bundle failed. |
||
33 | * |
||
34 | * @function parse |
||
35 | * @param {Object} body Body of the response |
||
36 | * @returns {Promise<CodingameError>} Reject with a CodingameError if parsing was successful |
||
37 | * @throws {Error} Throw is parsing failed |
||
38 | * @instance |
||
39 | */ |
||
40 | let parse = (body) => { |
||
41 | try { |
||
42 | let { |
||
43 | "error": { |
||
44 | "message": message, |
||
45 | "stacktrace": stacktrace |
||
46 | } |
||
47 | } = body; |
||
48 | if (Array.isArray(stacktrace)) { |
||
|
|||
49 | message += `\n`; |
||
50 | for (let st of stacktrace) { |
||
51 | message += `\t${st.container}:${st.line}:${st.function}`; |
||
52 | } |
||
53 | let error = new CodingameError(message); |
||
54 | return Promise.reject(error); |
||
55 | } else { |
||
56 | throw `Stacktrace in the error should be an array`; |
||
57 | } |
||
58 | } catch(error) { |
||
59 | let message = `The body is not of response type '${name}'\n`; |
||
60 | message += error.message; |
||
61 | throw new Error(message); |
||
62 | } |
||
63 | }; |
||
64 | |||
65 | export default { |
||
66 | "name": name, |
||
67 | "parse": parse |
||
68 | }; |
||
69 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.