Skip to content

Commit

Permalink
emulation logging tweaks (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia authored Oct 22, 2023
1 parent f88d21a commit 94a03a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions emulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func (s *EmulationHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {

data, err := io.ReadAll(r.Body)
if err != nil {
s.node.logger.log(newLogEntry(LogLevelInfo, "error reading emulation request body", map[string]any{"error": err.Error()}))
if len(data) >= maxBytesSize {
rw.WriteHeader(http.StatusRequestEntityTooLarge)
return
}
s.node.logger.log(newLogEntry(LogLevelError, "can't read emulation request body", map[string]any{"error": err.Error()}))
rw.WriteHeader(http.StatusInternalServerError)
return
}
Expand All @@ -69,7 +69,9 @@ func (s *EmulationHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
err = json.Unmarshal(data, &req)
}
if err != nil {
s.node.logger.log(newLogEntry(LogLevelInfo, "can't unmarshal emulation request", map[string]any{"req": &req, "error": err.Error()}))
if s.node.LogEnabled(LogLevelInfo) {
s.node.logger.log(newLogEntry(LogLevelInfo, "can't unmarshal emulation request", map[string]any{"error": err.Error(), "data": string(data)}))
}
rw.WriteHeader(http.StatusBadRequest)
return
}
Expand Down
2 changes: 1 addition & 1 deletion handler_http_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (h *HTTPStreamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error
requestData, err = io.ReadAll(r.Body)
if err != nil {
h.node.Log(NewLogEntry(LogLevelError, "error reading body", map[string]any{"error": err.Error()}))
h.node.Log(NewLogEntry(LogLevelInfo, "error reading http stream request body", map[string]any{"error": err.Error()}))
if len(requestData) >= maxBytesSize {
w.WriteHeader(http.StatusRequestEntityTooLarge)
return
Expand Down
2 changes: 1 addition & 1 deletion handler_sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func (h *SSEHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error
requestData, err = io.ReadAll(r.Body)
if err != nil {
h.node.Log(NewLogEntry(LogLevelInfo, "error reading sse request body", map[string]any{"error": err.Error()}))
if len(requestData) >= maxBytesSize {
w.WriteHeader(http.StatusRequestEntityTooLarge)
return
}
h.node.Log(NewLogEntry(LogLevelError, "error reading body", map[string]any{"error": err.Error()}))
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down

0 comments on commit 94a03a1

Please sign in to comment.