From 55cf6f431049d98a2559bb506320c1442df9a7f0 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Wed, 30 Oct 2024 14:17:10 -0300 Subject: [PATCH] fix(controller): check if usp message is of error type or null to avoid panic --- backend/services/controller/internal/api/usp.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/services/controller/internal/api/usp.go b/backend/services/controller/internal/api/usp.go index d6c961a..e552b27 100644 --- a/backend/services/controller/internal/api/usp.go +++ b/backend/services/controller/internal/api/usp.go @@ -61,6 +61,16 @@ func sendUspMsg(msg usp_msg.Msg, sn string, w http.ResponseWriter, nc *nats.Conn } body := receivedMsg.Body.GetResponse() + if body == nil { + errorMsg := receivedMsg.Body.GetError() + if errorMsg == nil { + w.WriteHeader(http.StatusInternalServerError) + log.Println("No response body or error") + return nil + } + w.Write(utils.Marshall(errorMsg)) + return nil + } switch body.RespType.(type) { case *usp_msg.Response_GetResp: