Skip to content

Commit 61a63ae

Browse files
committed
replace all hardcoded status code by their constant
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
1 parent 952d8a3 commit 61a63ae

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

rest/api.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ func (a *API) diagnostics(w http.ResponseWriter, r *http.Request) {
130130
ctx := r.Context()
131131
requestID, requestData, err := getRequestDataAndID(ctx)
132132
if err != nil {
133-
http.Error(w, err.Error(), 500)
133+
http.Error(w, err.Error(), http.StatusInternalServerError)
134134
return
135135
}
136136

137137
diagnostics, err := a.langServer.GetDiagnostics(requestID)
138138
if err != nil {
139-
http.Error(w, errors.Wrapf(err, "failed to get diagnostics").Error(), 500)
139+
http.Error(w, errors.Wrapf(err, "failed to get diagnostics").Error(), http.StatusInternalServerError)
140140
return
141141
}
142142

@@ -153,12 +153,12 @@ func (a *API) hover(w http.ResponseWriter, r *http.Request) {
153153
ctx := r.Context()
154154
requestID, requestData, err := getRequestDataAndID(ctx)
155155
if err != nil {
156-
http.Error(w, err.Error(), 500)
156+
http.Error(w, err.Error(), http.StatusInternalServerError)
157157
return
158158
}
159159
position, err := requestData.returnPosition()
160160
if err != nil {
161-
http.Error(w, err.Error(), 400)
161+
http.Error(w, err.Error(), http.StatusBadRequest)
162162
return
163163
}
164164

@@ -171,7 +171,7 @@ func (a *API) hover(w http.ResponseWriter, r *http.Request) {
171171
},
172172
})
173173
if err != nil {
174-
http.Error(w, errors.Wrapf(err, "failed to get hover info").Error(), 500)
174+
http.Error(w, errors.Wrapf(err, "failed to get hover info").Error(), http.StatusInternalServerError)
175175
return
176176
}
177177

@@ -182,12 +182,12 @@ func (a *API) completion(w http.ResponseWriter, r *http.Request) {
182182
ctx := r.Context()
183183
requestID, requestData, err := getRequestDataAndID(ctx)
184184
if err != nil {
185-
http.Error(w, err.Error(), 500)
185+
http.Error(w, err.Error(), http.StatusInternalServerError)
186186
return
187187
}
188188
position, err := requestData.returnPosition()
189189
if err != nil {
190-
http.Error(w, err.Error(), 400)
190+
http.Error(w, err.Error(), http.StatusBadRequest)
191191
return
192192
}
193193

@@ -217,12 +217,12 @@ func (a *API) signature(w http.ResponseWriter, r *http.Request) {
217217
ctx := r.Context()
218218
requestID, requestData, err := getRequestDataAndID(ctx)
219219
if err != nil {
220-
http.Error(w, err.Error(), 500)
220+
http.Error(w, err.Error(), http.StatusInternalServerError)
221221
return
222222
}
223223
position, err := requestData.returnPosition()
224224
if err != nil {
225-
http.Error(w, err.Error(), 400)
225+
http.Error(w, err.Error(), http.StatusBadRequest)
226226
return
227227
}
228228

rest/middleware.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func manageDocumentMiddleware(langServer langserver.HeadlessServer) middlewareFu
8484
// start to generate an unique ID for the given request
8585
id, err := uuid.NewRandom()
8686
if err != nil {
87-
http.Error(w, err.Error(), 500)
87+
http.Error(w, err.Error(), http.StatusInternalServerError)
8888
return
8989
}
9090
requestID := protocol.DocumentURI(id.String())
@@ -96,10 +96,10 @@ func manageDocumentMiddleware(langServer langserver.HeadlessServer) middlewareFu
9696
if err := json.NewDecoder(r.Body).Decode(data); err != nil {
9797
if err == io.EOF {
9898
// this case is used just in order to have a proper error message instead of just "EOF"
99-
http.Error(w, fmt.Sprint("body not present"), 400)
99+
http.Error(w, fmt.Sprint("body not present"), http.StatusBadRequest)
100100
return
101101
}
102-
http.Error(w, err.Error(), 400)
102+
http.Error(w, err.Error(), http.StatusBadRequest)
103103
return
104104
}
105105
// inject the data unmarshalled to avoid to have to decode it later

0 commit comments

Comments
 (0)