Skip to content

Commit

Permalink
fixed: return bad request when client EOF during read.
Browse files Browse the repository at this point in the history
  • Loading branch information
primalmotion committed Nov 12, 2019
1 parent e203ff4 commit 5d0486d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,26 @@ func NewRequestFromHTTPRequest(req *http.Request, manager ModelManager) (*Reques
case http.MethodPatch:
operation = OperationPatch
data, err = ioutil.ReadAll(req.Body)
defer req.Body.Close() // nolint: errcheck
if err != nil {
return nil, err
return nil, NewError("Bad Request", fmt.Sprintf("Unable to read body of request: %s", err), "elemental", http.StatusBadRequest)
}
defer req.Body.Close() // nolint: errcheck

case http.MethodPost:
operation = OperationCreate
data, err = ioutil.ReadAll(req.Body)
defer req.Body.Close() // nolint: errcheck
if err != nil {
return nil, err
return nil, NewError("Bad Request", fmt.Sprintf("Unable to read body of request: %s", err), "elemental", http.StatusBadRequest)
}
defer req.Body.Close() // nolint: errcheck

case http.MethodPut:
operation = OperationUpdate
data, err = ioutil.ReadAll(req.Body)
defer req.Body.Close() // nolint: errcheck
if err != nil {
return nil, err
return nil, NewError("Bad Request", fmt.Sprintf("Unable to read body of request: %s", err), "elemental", http.StatusBadRequest)
}
defer req.Body.Close() // nolint: errcheck
}

var page, pageSize, limit int
Expand Down

0 comments on commit 5d0486d

Please sign in to comment.