Skip to content

Commit

Permalink
型を変更して使いやすくする
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Jan 30, 2024
1 parent c9b02bb commit a4be6fe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions amazon_transcribe_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion speech_to_text_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions test_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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).
Expand Down

0 comments on commit a4be6fe

Please sign in to comment.