From 5415a6936f74b9643c2867de8c06924014a289e9 Mon Sep 17 00:00:00 2001 From: Janishar Ali Date: Tue, 2 Jul 2024 04:10:11 +0530 Subject: [PATCH] send nats error message for api error --- arch/micro/sender.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/micro/sender.go b/arch/micro/sender.go index ae9bc37..f7e6882 100644 --- a/arch/micro/sender.go +++ b/arch/micro/sender.go @@ -1,5 +1,12 @@ package micro +import ( + "errors" + "fmt" + + "github.com/unusualcodeorg/goserve/arch/network" +) + type sender struct{} func NewMessageSender() MessageSender { @@ -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)) }