@@ -30,42 +30,33 @@ const getHeaders = (authenticationToken) => ({
30
30
*/
31
31
export const downloadInput = async ( year , day , authenticationToken ) => {
32
32
logger . debug ( 'downloading input file for year: %s, day: %s' , year , day ) ;
33
-
34
33
if ( ! authenticationToken ) {
35
34
throw new Error (
36
35
'Authentication Token is required to query advent of code.'
37
36
) ;
38
37
}
39
38
40
- // query api
41
39
const url = puzzleInputUrl ( year , day ) ;
42
40
logger . debug ( 'querying url for input: %s' , url ) ;
43
41
const response = await fetch ( url , {
44
42
headers : getHeaders ( authenticationToken ) ,
45
43
} ) ;
46
44
47
- // bad request, authentication failed.
48
45
if ( response . status === 400 ) {
49
46
throw new NotAuthorizedError ( ) ;
50
47
}
51
- // not found, invalid day or year.
52
48
if ( response . status === 404 ) {
53
49
throw new PuzzleNotFoundError ( year , day ) ;
54
50
}
55
- // handle all other error status codes
56
51
if ( ! response . ok ) {
57
52
throw new InternalServerError ( response . status , response . statusText ) ;
58
53
}
59
54
60
- // expect text of response is the input.
61
55
const text = await response . text ( ) ;
62
-
63
56
if ( ! text ) {
64
57
throw new Error ( 'Advent of code returned empty input' ) ;
65
58
}
66
-
67
59
logger . debug ( 'downloaded: %s' , sizeOfStringInKb ( text ) ) ;
68
-
69
60
return text ;
70
61
} ;
71
62
0 commit comments