@@ -9,14 +9,14 @@ app.post("/eslint/format", async (req, res) => {
9
9
const ESLintOverrideConfigFile = format_data . eslint_override_config_file ;
10
10
11
11
if ( ! ESLintOverrideConfig && ! ESLintOverrideConfigFile ) {
12
- res . status ( 501 ) . send ( "Error while formatting: No config provided" ) ;
12
+ res . status ( 400 ) . send ( "Error while formatting: No config provided" ) ;
13
13
return ;
14
14
}
15
15
16
16
const filePath = format_data . file_path ;
17
17
18
18
if ( ! filePath ) {
19
- res . status ( 501 ) . send ( "Error while formatting: No file path provided" ) ;
19
+ res . status ( 400 ) . send ( "Error while formatting: No file path provided" ) ;
20
20
return ;
21
21
}
22
22
@@ -41,34 +41,40 @@ app.post("/eslint/format", async (req, res) => {
41
41
eval ( "ESLintOptions.overrideConfig = " + ESLintOverrideConfig ) ;
42
42
}
43
43
44
- console . log ( "using options: " + JSON . stringify ( ESLintOptions ) ) ;
45
- console . log ( "format input: " , format_data . file_content ) ;
44
+ if ( debug_serve ) {
45
+ console . log ( "using options: " + JSON . stringify ( ESLintOptions ) ) ;
46
+ console . log ( "format input: " , format_data . file_content ) ;
47
+ }
46
48
47
49
const eslint = new ESLint ( ESLintOptions ) ;
48
50
49
51
50
52
const lintTextOptions = {
51
53
filePath : filePath ,
52
54
}
53
- console . log ( "lintTextOptions" , lintTextOptions ) ;
55
+ if ( debug_serve ) {
56
+ console . log ( "lintTextOptions" , lintTextOptions ) ;
57
+ }
54
58
55
59
// LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type
56
60
const results = await eslint . lintText ( format_data . file_content , lintTextOptions ) ;
57
61
if ( results . length !== 1 ) {
58
- res . status ( 501 ) . send ( "Error while formatting: Unexpected number of results: " + JSON . stringify ( results ) ) ;
62
+ res . status ( 500 ) . send ( "Error while formatting: Unexpected number of results: " + JSON . stringify ( results ) ) ;
59
63
return ;
60
64
}
61
65
const result = results [ 0 ] ;
62
- console . log ( "result: " + JSON . stringify ( result ) ) ;
66
+ if ( debug_serve ) {
67
+ console . log ( "result: " + JSON . stringify ( result ) ) ;
68
+ }
63
69
if ( result . fatalErrorCount && result . fatalErrorCount > 0 ) {
64
- res . status ( 501 ) . send ( "Fatal error while formatting: " + JSON . stringify ( result . messages ) ) ;
70
+ res . status ( 500 ) . send ( "Fatal error while formatting: " + JSON . stringify ( result . messages ) ) ;
65
71
return ;
66
72
}
67
73
const formatted = result . output || result . source || format_data . file_content ;
68
74
res . set ( "Content-Type" , "text/plain" ) ;
69
75
res . send ( formatted ) ;
70
76
} catch ( err ) {
71
77
console . log ( "error" , err ) ;
72
- res . status ( 501 ) . send ( "Error while formatting: " + err ) ;
78
+ res . status ( 500 ) . send ( "Error while formatting: " + err ) ;
73
79
}
74
80
} ) ;
0 commit comments