Skip to content

Commit

Permalink
Ensure that handler responds with an http 200
Browse files Browse the repository at this point in the history
  • Loading branch information
Buddhike de Silva committed Mar 28, 2020
1 parent 20348be commit 45c3b5f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/http_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lib
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"

Expand All @@ -25,11 +26,15 @@ func (d *HttpDispatcher) Dispatch(m *Message) error {
}

defer response.Body.Close()
_, err = ioutil.ReadAll(response.Body)
body, err := ioutil.ReadAll(response.Body)

if err != nil {
return errors.WithStack(err)
}

if response.StatusCode != 200 {
return errors.WithStack(errors.New(fmt.Sprintf("error response from handler %d: %s", response.StatusCode, string(body))))
}
return nil
}

Expand Down

0 comments on commit 45c3b5f

Please sign in to comment.