diff --git a/amazon_transcribe_handler.go b/amazon_transcribe_handler.go index fe6866c..5cff578 100644 --- a/amazon_transcribe_handler.go +++ b/amazon_transcribe_handler.go @@ -103,7 +103,7 @@ 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 { - if err := encoder.Encode(NewSuzuErrorResponse(err.Error())); err != nil { + if err := encoder.Encode(NewSuzuErrorResponse(err)); err != nil { zlog.Error(). Err(err). Str("channel_id", h.ChannelID). @@ -149,8 +149,7 @@ func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader) } if err := stream.Err(); err != nil { - errResponse := NewSuzuErrorResponse(err.Error()) - if err := encoder.Encode(errResponse); err != nil { + if err := encoder.Encode(NewSuzuErrorResponse(err)); err != nil { zlog.Error(). Err(err). Str("channel_id", h.ChannelID). diff --git a/handler.go b/handler.go index 5e7b8ba..c348a42 100644 --- a/handler.go +++ b/handler.go @@ -30,10 +30,10 @@ type TranscriptionResult struct { Type string `json:"type"` } -func NewSuzuErrorResponse(message string) TranscriptionResult { +func NewSuzuErrorResponse(err error) TranscriptionResult { return TranscriptionResult{ Type: "error", - Reason: message, + Reason: err.Error(), } } diff --git a/speech_to_text_handler.go b/speech_to_text_handler.go index 5681390..4441b30 100644 --- a/speech_to_text_handler.go +++ b/speech_to_text_handler.go @@ -144,7 +144,7 @@ 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 { - if err := encoder.Encode(NewSuzuErrorResponse(err.Error())); err != nil { + if err := encoder.Encode(NewSuzuErrorResponse(err)); err != nil { zlog.Error(). Err(err). Str("channel_id", h.ChannelID). diff --git a/test_handler.go b/test_handler.go index 15fc137..a8c3912 100644 --- a/test_handler.go +++ b/test_handler.go @@ -63,7 +63,7 @@ func (h *TestHandler) Handle(ctx context.Context, reader io.Reader) (*io.PipeRea n, err := reader.Read(buf) if err != nil { if err != io.EOF { - if err := encoder.Encode(NewSuzuErrorResponse(err.Error())); err != nil { + if err := encoder.Encode(NewSuzuErrorResponse(err)); err != nil { zlog.Error(). Err(err). Str("channel_id", h.ChannelID). @@ -82,7 +82,7 @@ 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 { - if err := encoder.Encode(NewSuzuErrorResponse(err.Error())); err != nil { + if err := encoder.Encode(NewSuzuErrorResponse(err)); err != nil { zlog.Error(). Err(err). Str("channel_id", h.ChannelID).