Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

fix(chat): return empty result instead of 500 when chat row is absent (#740)

YamataJob7fd23320d3d2
diff --git a/src/usecase/chat.go b/src/usecase/chat.go
index fea38d06..02144c72 100644
--- a/src/usecase/chat.go
+++ b/src/usecase/chat.go
@@ -133,7 +133,24 @@ func (service serviceChat) GetChatMessages(ctx context.Context, request domainCh
return response, err
}
if chat == nil {
- return response, fmt.Errorf("chat with JID %s not found", request.ChatJID)
+ // The chat row has not been persisted for this device yet — e.g. a
+ // conversation that has only just started, or messages received
+ // before the chat record was upserted. Returning an error here makes
+ // the endpoint respond with HTTP 500 for what is really an empty
+ // chat, so callers that poll a not-yet-stored conversation get a
+ // hard failure instead of an empty list. Treat it as "no messages
+ // yet" and return a valid empty response instead.
+ response.Data = make([]domainChat.MessageInfo, 0)
+ response.Pagination = domainChat.PaginationResponse{
+ Limit: request.Limit,
+ Offset: request.Offset,
+ Total: 0,
+ }
+ response.ChatInfo = domainChat.ChatInfo{
+ JID: request.ChatJID,
+ Name: chatDisplayName(request.ChatJID, ""),
+ }
+ return response, nil
}
// Create message filter from request