Skip to content

Commit

Permalink
ログに出力される status code が実際のものから変わるため、stream 処理開始後はエラーをそのまま返す
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Jan 10, 2024
1 parent 47bf4ff commit eb3d3ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *Server) createSpeechHandler(serviceType string, onResultFunc func(conte
Str("channel_id", h.SoraChannelID).
Str("connection_id", h.SoraConnectionID).
Send()
return echo.NewHTTPError(499)
return err
} else if errors.Is(err, ErrServerDisconnected) {
if *s.config.Retry {
// サーバから切断されたが再度接続できる可能性があるため、接続を試みる
Expand All @@ -173,7 +173,7 @@ func (s *Server) createSpeechHandler(serviceType string, onResultFunc func(conte
Str("channel_id", h.SoraChannelID).
Str("connection_id", h.SoraConnectionID).
Send()
return echo.NewHTTPError(http.StatusInternalServerError)
return err
}
}

Expand All @@ -182,8 +182,8 @@ func (s *Server) createSpeechHandler(serviceType string, onResultFunc func(conte
Str("channel_id", h.SoraChannelID).
Str("connection_id", h.SoraConnectionID).
Send()
// サーバから切断されたが再度の接続が期待できない場合、または、想定外のエラーの場合は InternalServerError
return echo.NewHTTPError(http.StatusInternalServerError)
// サーバから切断されたが再度の接続が期待できない場合
return err
}

// メッセージが空でない場合はクライアントに結果を送信する
Expand All @@ -194,7 +194,7 @@ func (s *Server) createSpeechHandler(serviceType string, onResultFunc func(conte
Str("channel_id", h.SoraChannelID).
Str("connection_id", h.SoraConnectionID).
Send()
return echo.NewHTTPError(http.StatusInternalServerError)
return err
}
c.Response().Flush()
}
Expand Down
4 changes: 2 additions & 2 deletions test_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestSpeechHandler(t *testing.T) {
h := s.createSpeechHandler(serviceType, nil)
err = h(c)
if assert.Error(t, err) {
assert.Equal(t, http.StatusInternalServerError, err.(*echo.HTTPError).Code)
assert.Equal(t, "packet read error", err.Error())
}

pw.Close()
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestSpeechHandler(t *testing.T) {
})
err := h(c)
if assert.Error(t, err) {
assert.Equal(t, http.StatusInternalServerError, err.(*echo.HTTPError).Code)
assert.Equal(t, "ON-RESULT-ERROR", err.Error())
}

})
Expand Down

0 comments on commit eb3d3ca

Please sign in to comment.