Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #310 from neotoolkit/fix/EOF
Browse files Browse the repository at this point in the history
fix(server): fix EOF error
  • Loading branch information
sashamelentyev authored Feb 10, 2022
2 parents 52282b9 + 6ff3deb commit 8bb1b39
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/goccy/go-yaml v1.9.5
github.com/lamoda/gonkey v1.13.2
github.com/neotoolkit/faker v0.1.2
github.com/neotoolkit/openapi v0.7.0
github.com/neotoolkit/openapi v0.7.1
github.com/rs/zerolog v1.26.1
github.com/stretchr/testify v1.7.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/neotoolkit/faker v0.1.2 h1:4/Xbk8DssKBZFUA/wIpWeGvWM9KMlQoitLFck3KROdg=
github.com/neotoolkit/faker v0.1.2/go.mod h1:ChsI+y4MR3t1Ybbt0ktUXqDVJTq9w9oXuL59jJ5ufF4=
github.com/neotoolkit/openapi v0.7.0 h1:y/AGnqVMgG6h1vps6e5lCEVYlim99PIiE+zvxH0Xduc=
github.com/neotoolkit/openapi v0.7.0/go.mod h1:gjP+o4cR08QAZaVFIvJP6rsBoBlqz34hovntey1r4ks=
github.com/neotoolkit/openapi v0.7.1 h1:adKR3bNjPznIwLDHffSZ6IUrsxMmDcfGs30VeYiRvbc=
github.com/neotoolkit/openapi v0.7.1/go.mod h1:gjP+o4cR08QAZaVFIvJP6rsBoBlqz34hovntey1r4ks=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
6 changes: 5 additions & 1 deletion internal/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *Server) Handler(w http.ResponseWriter, r *http.Request) {

response, ok, err := s.Handlers.Get(path, r.Method, r.Body)
if ok {
if _, ok := err.(*json.SyntaxError); ok || errors.Is(err, api.ErrEmptyRequireField) {
if _, ok := err.(*json.SyntaxError); ok || errors.Is(err, api.ErrEmptyRequireField) || err == io.EOF {
w.WriteHeader(http.StatusBadRequest)

return
Expand Down Expand Up @@ -77,6 +77,10 @@ func (h Handlers) Get(path, method string, body io.ReadCloser) (api.Response, bo
return api.Response{}, true, err
}

if err == io.EOF {
return api.Response{}, true, err
}

if _, ok := err.(*json.SyntaxError); ok {
return api.Response{}, true, err
}
Expand Down

0 comments on commit 8bb1b39

Please sign in to comment.