Skip to content

Commit

Permalink
send nats error message for api error
Browse files Browse the repository at this point in the history
  • Loading branch information
janishar committed Jul 1, 2024
1 parent 754b336 commit 5415a69
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions arch/micro/sender.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package micro

import (
"errors"
"fmt"

"github.com/unusualcodeorg/goserve/arch/network"
)

type sender struct{}

func NewMessageSender() MessageSender {
Expand All @@ -21,5 +28,10 @@ func (s *send) Message(data any) {
}

func (s *send) Error(err error) {
if apiError, ok := err.(network.ApiError); ok {
msg := fmt.Sprintf("%d:%s", apiError.GetCode(), apiError.GetMessage())
s.natsRequest.RespondJSON(NewAnyMessage(nil, errors.New(msg)))
return
}
s.natsRequest.RespondJSON(NewAnyMessage(nil, err))
}

0 comments on commit 5415a69

Please sign in to comment.