From d46fc46de1338aea1aa410264e3dca358b482983 Mon Sep 17 00:00:00 2001
From: thijsheijden <hi@thijsheijden.nl>
Date: Mon, 13 Dec 2021 13:32:51 +0100
Subject: [PATCH] Added panic intercept method to RabbitMQ message handler

---
 internal/usecases/consume/handlemessage.go | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/internal/usecases/consume/handlemessage.go b/internal/usecases/consume/handlemessage.go
index 424df72..f751492 100644
--- a/internal/usecases/consume/handlemessage.go
+++ b/internal/usecases/consume/handlemessage.go
@@ -24,6 +24,14 @@ HandleMessage gets called when a message is received
 	msg: *broker.Message, the message to be handled
 */
 func (s *Service) HandleMessage(msg *broker.Message) {
+
+	// Defer a panic intercepting function
+	defer func() {
+		if err := recover(); err != nil {
+			log.Printf("PANIC: %e", err.(error))
+		}
+	}()
+
 	// Grab the headers from the message
 	sessionID, clientID, queryID, err := getHeaders(&msg.Headers)
 	if err != nil {
-- 
GitLab