@@ -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,8 +41,10 @@ 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
@@ -55,20 +57,22 @@ app.post("/eslint/format", async (req, res) => {
55
57
// LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type
56
58
const results = await eslint . lintText ( format_data . file_content , lintTextOptions ) ;
57
59
if ( results . length !== 1 ) {
58
- res . status ( 501 ) . send ( "Error while formatting: Unexpected number of results: " + JSON . stringify ( results ) ) ;
60
+ res . status ( 500 ) . send ( "Error while formatting: Unexpected number of results: " + JSON . stringify ( results ) ) ;
59
61
return ;
60
62
}
61
63
const result = results [ 0 ] ;
62
- console . log ( "result: " + JSON . stringify ( result ) ) ;
64
+ if ( debug_serve ) {
65
+ console . log ( "result: " + JSON . stringify ( result ) ) ;
66
+ }
63
67
if ( result . fatalErrorCount && result . fatalErrorCount > 0 ) {
64
- res . status ( 501 ) . send ( "Fatal error while formatting: " + JSON . stringify ( result . messages ) ) ;
68
+ res . status ( 500 ) . send ( "Fatal error while formatting: " + JSON . stringify ( result . messages ) ) ;
65
69
return ;
66
70
}
67
71
const formatted = result . output || result . source || format_data . file_content ;
68
72
res . set ( "Content-Type" , "text/plain" ) ;
69
73
res . send ( formatted ) ;
70
74
} catch ( err ) {
71
75
console . log ( "error" , err ) ;
72
- res . status ( 501 ) . send ( "Error while formatting: " + err ) ;
76
+ res . status ( 500 ) . send ( "Error while formatting: " + err ) ;
73
77
}
74
78
} ) ;
0 commit comments