Skip to content

Commit b8f19af

Browse files
committed
Simplify function call, error is allways BadStatus
1 parent 8db25c4 commit b8f19af

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

receiver/libhoneyreceiver/receiver.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ func (r *libhoneyReceiver) handleAuth(resp http.ResponseWriter, req *http.Reques
172172
}
173173

174174
// writeLibhoneyError writes a bad request error response in the appropriate format for libhoney clients
175-
func writeLibhoneyError(resp http.ResponseWriter, enc encoder.Encoder, statusCode int, errorMsg string) {
175+
func writeLibhoneyError(resp http.ResponseWriter, enc encoder.Encoder, errorMsg string) {
176176
errorResponse := []response.ResponseInBatch{{
177177
ErrorStr: errorMsg,
178-
Status: statusCode,
178+
Status: http.StatusBadRequest,
179179
}}
180180

181181
var responseBody []byte
@@ -196,7 +196,7 @@ func writeLibhoneyError(resp http.ResponseWriter, enc encoder.Encoder, statusCod
196196
errorutil.HTTPError(resp, err)
197197
return
198198
}
199-
writeResponse(resp, contentType, statusCode, responseBody)
199+
writeResponse(resp, contentType, http.StatusBadRequest, responseBody)
200200
}
201201

202202
func (r *libhoneyReceiver) handleEvent(resp http.ResponseWriter, req *http.Request) {
@@ -220,12 +220,12 @@ func (r *libhoneyReceiver) handleEvent(resp http.ResponseWriter, req *http.Reque
220220
body, err := io.ReadAll(req.Body)
221221
if err != nil {
222222
r.settings.Logger.Error("Failed to read request body", zap.Error(err))
223-
writeLibhoneyError(resp, enc, http.StatusBadRequest, "failed to read request body")
223+
writeLibhoneyError(resp, enc, "failed to read request body")
224224
return
225225
}
226226
if err = req.Body.Close(); err != nil {
227227
r.settings.Logger.Error("Failed to close request body", zap.Error(err))
228-
writeLibhoneyError(resp, enc, http.StatusBadRequest, "failed to close request body")
228+
writeLibhoneyError(resp, enc, "failed to close request body")
229229
return
230230
}
231231
libhoneyevents := make([]libhoneyevent.LibhoneyEvent, 0)
@@ -236,7 +236,7 @@ func (r *libhoneyReceiver) handleEvent(resp http.ResponseWriter, req *http.Reque
236236
err = decoder.Decode(&libhoneyevents)
237237
if err != nil {
238238
r.settings.Logger.Info("messagepack decoding failed")
239-
writeLibhoneyError(resp, enc, http.StatusBadRequest, "failed to unmarshal msgpack")
239+
writeLibhoneyError(resp, enc, "failed to unmarshal msgpack")
240240
return
241241
}
242242
// Post-process msgpack events to ensure timestamps are set
@@ -261,7 +261,7 @@ func (r *libhoneyReceiver) handleEvent(resp http.ResponseWriter, req *http.Reque
261261
case encoder.JSONContentType:
262262
err = json.Unmarshal(body, &libhoneyevents)
263263
if err != nil {
264-
writeLibhoneyError(resp, enc, http.StatusBadRequest, "failed to unmarshal JSON")
264+
writeLibhoneyError(resp, enc, "failed to unmarshal JSON")
265265
return
266266
}
267267
if len(libhoneyevents) > 0 {

0 commit comments

Comments
 (0)