1 | /** |
||
2 | * @file Module 'codingame/parse' |
||
3 | * @author woshilapin <[email protected]> |
||
4 | */ |
||
5 | /** |
||
6 | * Parse response coming from Codingame's services |
||
7 | * @module codingame/parse |
||
8 | */ |
||
9 | import CodingameError from './error.js'; |
||
10 | import parse_frames from './parsers/frames.js'; |
||
11 | import parse_failcompile from './parsers/failcompile.js'; |
||
12 | import parse_failexpected from './parsers/failexpected.js'; |
||
13 | import parse_success from './parsers/success.js'; |
||
14 | |||
15 | let parsers = []; |
||
16 | parsers.push(parse_frames); |
||
17 | parsers.push(parse_failcompile); |
||
18 | parsers.push(parse_failexpected); |
||
19 | parsers.push(parse_success); |
||
20 | |||
21 | /** |
||
22 | * Parse response coming from tests sent to Codingame website |
||
23 | * |
||
24 | * @name parse |
||
25 | * @function |
||
26 | * @param {Object} response Body of the response |
||
27 | * @returns {Promise<Object|CodingameError>} Resolve if test is a success, reject with a CodingameError if test failed or parsing was impossible |
||
28 | */ |
||
29 | let parse = (response) => { |
||
30 | let body = response.success; |
||
31 | for (let parser of parsers) { |
||
32 | try { |
||
33 | let promise = parser.parse(body); |
||
34 | return Promise.resolve(promise); // Resume loop if no Error has been thrown |
||
35 | } catch (error) { |
||
36 | continue; |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
37 | } |
||
38 | } |
||
39 | let message = `Unknown error. Codingame may have changed its API. Please contact 'codingame-connector' developer.`; |
||
40 | let error = new Error(message); |
||
0 ignored issues
–
show
Comprehensibility
Naming
Best Practice
introduced
by
The variable
error already seems to be declared on line 35 . Consider using another variable name or omitting the var keyword.
This check looks for variables that are declared in multiple lines. There may be several reasons for this. In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs. If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared. ![]() |
|||
41 | return Promise.reject(error); |
||
42 | }; |
||
43 | |||
44 | export default { |
||
45 | "parse": parse |
||
46 | }; |
||
47 |