tobyweston / temperature-machine

Data logger for multiple DS18B20 temperature sensors on one or more machines
Apache License 2.0
67 stars 22 forks source link

UnexpectedError(Failed attempting to connect to localhost/127.0.0.1 to send Measurement logs #52

Closed tobyweston closed 6 years ago

tobyweston commented 6 years ago

We're often seeing something like the following in the client logs.

-\/(UnexpectedError(Failed attempting to connect to localhost/127.0.0.1 to send Measurement(Host(example),1509221361 seconds,List(SensorReading(28-0115910f5eff,Temperature(19.75))))

Error was: org.http4s.MalformedMessageBodyFailure: Malformed message body: Invalid JSON: empty body
Payload was: '{
  "host" : "example",
  "seconds" : 1509221361,
  "sensors" : [
    {
      "name" : "28-0115910f5eff",
      "temperature" : {
        "celsius" : 19.75
      }
    }
  ]
}'

This is a bug where a non-200 response from the server is being incorrectly captured as a client (connection) error. The log detail about the malformed message body doesn't make any sense because it looks like it's saying the client couldn't connect because of a bad payload, even though the printed payload is valid JSON.

In fact, what's happening is the server is responding with say, a 500 Internal Server Error and the code that tries to display the response body is throwing an uncaught exception cause the default Task error handler (withHandler) to capture it and deal with it.

tobyweston commented 6 years ago

Fixed with the above