Skip to content

Commit

Permalink
check the errors
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Jun 19, 2023
1 parent 423bf88 commit 3bc187e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ridgenative.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ func (f *lambdaFunction) lambdaHandlerStreaming(ctx context.Context, req *reques
rw := newStreamingResponseWriter(w)
defer func() {
if v := recover(); v != nil {
rw.closeWithError(lambdaPanicResponse(v))
_ = rw.closeWithError(lambdaPanicResponse(v))
} else {
rw.close()
_ = rw.close()
}
}()
f.mux.ServeHTTP(rw, r)
Expand Down
24 changes: 18 additions & 6 deletions ridgenative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,9 @@ func TestLambdaHandlerStreaming(t *testing.T) {
t.Run("normal", func(t *testing.T) {
l := newLambdaFunction(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
io.WriteString(w, `{"hello":"world"}`)
if _, err := io.WriteString(w, `{"hello":"world"}`); err != nil {
t.Error(err)
}
}))
r, w := io.Pipe()
contentType, err := l.lambdaHandlerStreaming(context.Background(), &request{
Expand Down Expand Up @@ -794,8 +796,12 @@ func TestLambdaHandlerStreaming(t *testing.T) {

// Writes to ResponseWriter are buffered,
// so multiple writes to ResponseWriter become a single write to the pipe
io.WriteString(w, `{"hello":`)
io.WriteString(w, `"world"}`)
if _, err := io.WriteString(w, `{"hello":`); err != nil {
t.Error(err)
}
if _, err := io.WriteString(w, `"world"}`); err != nil {
t.Error(err)
}
}))
r, w := io.Pipe()
contentType, err := l.lambdaHandlerStreaming(context.Background(), &request{
Expand Down Expand Up @@ -851,9 +857,13 @@ func TestLambdaHandlerStreaming(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

io.WriteString(w, `{"hello":`)
if _, err := io.WriteString(w, `{"hello":`); err != nil {
t.Error(err)
}
f.Flush()
io.WriteString(w, `"world"}`)
if _, err := io.WriteString(w, `"world"}`); err != nil {
t.Error(err)
}
}))
r, w := io.Pipe()
contentType, err := l.lambdaHandlerStreaming(context.Background(), &request{
Expand Down Expand Up @@ -911,7 +921,9 @@ func TestLambdaHandlerStreaming(t *testing.T) {

t.Run("detect content-type", func(t *testing.T) {
l := newLambdaFunction(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, `<html></html>`)
if _, err := io.WriteString(w, `<html></html>`); err != nil {
t.Error(err)
}
}))
r, w := io.Pipe()
contentType, err := l.lambdaHandlerStreaming(context.Background(), &request{
Expand Down

0 comments on commit 3bc187e

Please sign in to comment.