Skip to content

Commit

Permalink
エラーメッセージ送信時のエラーをログに出力する
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Jan 24, 2024
1 parent c3bf4d2 commit 41562cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
9 changes: 6 additions & 3 deletions amazon_transcribe_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader)
case *transcribestreamingservice.TranscriptEvent:
if h.OnResultFunc != nil {
if err := h.OnResultFunc(ctx, w, h.ChannelID, h.ConnectionID, h.LanguageCode, e.Transcript.Results); err != nil {
errResponse := NewSuzuErrorResponse(err.Error())
if err := encoder.Encode(errResponse); err != nil {
// TODO: ログを書く
if err := encoder.Encode(NewSuzuErrorResponse(err.Error())); err != nil {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
}
w.CloseWithError(err)
return
Expand Down
9 changes: 6 additions & 3 deletions speech_to_text_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ func (h *SpeechToTextHandler) Handle(ctx context.Context, reader io.Reader) (*io

if h.OnResultFunc != nil {
if err := h.OnResultFunc(ctx, w, h.ChannelID, h.ConnectionID, h.LanguageCode, resp.Results); err != nil {
errResponse := NewSuzuErrorResponse(err.Error())
if err := encoder.Encode(errResponse); err != nil {
// TODO: ログを書く
if err := encoder.Encode(NewSuzuErrorResponse(err.Error())); err != nil {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
}
w.CloseWithError(err)
return
Expand Down
20 changes: 14 additions & 6 deletions test_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"fmt"
"io"

zlog "github.com/rs/zerolog/log"
)

func init() {
Expand Down Expand Up @@ -61,9 +63,12 @@ func (h *TestHandler) Handle(ctx context.Context, reader io.Reader) (*io.PipeRea
n, err := reader.Read(buf)
if err != nil {
if err != io.EOF {
errResponse := NewSuzuErrorResponse(err.Error())
if err := encoder.Encode(errResponse); err != nil {
// TODO: ログを書く
if err := encoder.Encode(NewSuzuErrorResponse(err.Error())); err != nil {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
}
}
w.CloseWithError(err)
Expand All @@ -77,9 +82,12 @@ func (h *TestHandler) Handle(ctx context.Context, reader io.Reader) (*io.PipeRea

if h.OnResultFunc != nil {
if err := h.OnResultFunc(ctx, w, h.ChannelID, h.ConnectionID, h.LanguageCode, result); err != nil {
errResponse := NewSuzuErrorResponse(err.Error())
if err := encoder.Encode(errResponse); err != nil {
// TODO: ログを書く
if err := encoder.Encode(NewSuzuErrorResponse(err.Error())); err != nil {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
}
w.CloseWithError(err)
return
Expand Down

0 comments on commit 41562cb

Please sign in to comment.