Skip to content

Commit

Permalink
Handle some error
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
Jianhui Zhao committed Apr 27, 2019
1 parent 2b10e61 commit 87a9248
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package main
import (
"fmt"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -94,10 +95,15 @@ func serveCmd(br *Broker, w http.ResponseWriter, r *http.Request) {
return
}

body, _ := ioutil.ReadAll(r.Body)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Error(err)
cmdErrReply(RTTY_CMD_ERR_INVALID, w)
return
}

cmdInfo := CommandInfo{}
err := jsoniter.Unmarshal(body, &cmdInfo)
err = jsoniter.Unmarshal(body, &cmdInfo)
if err != nil || cmdInfo.Cmd == "" || cmdInfo.Devid == "" {
cmdErrReply(RTTY_CMD_ERR_INVALID, w)
return
Expand Down

0 comments on commit 87a9248

Please sign in to comment.