Skip to content
Snippets Groups Projects
Commit 7c74cad3 authored by Lelieveld,J.R.J. (Joris)'s avatar Lelieveld,J.R.J. (Joris)
Browse files

Merge branch 'panic-intercept' into 'develop'

Added panic intercept method to RabbitMQ message handler

See merge request !4
parents 4553d2b1 5f28df4a
No related branches found
No related tags found
2 merge requests!6End of SWP 2 Merge,!4Added panic intercept method to RabbitMQ message handler
Pipeline #112757 canceled
......@@ -24,6 +24,7 @@ HandleMessage gets called when a message is received
msg: *broker.Message, the message to be handled
*/
func (s *Service) HandleMessage(msg *broker.Message) {
// Grab the headers from the message
sessionID, clientID, queryID, err := getHeaders(&msg.Headers)
if err != nil {
......@@ -32,6 +33,15 @@ func (s *Service) HandleMessage(msg *broker.Message) {
}
s.publishStatus("Received", sessionID, queryID)
// Defer a panic intercepting function
defer func(sessionID, queryID *string) {
if err := recover(); err != nil {
log.Printf("PANIC: %e", err.(error))
s.publishStatus("Critical Error", sessionID, queryID)
}
}(sessionID, queryID)
// Unmarshall the incoming message into an IncomingJSONQuery object
JSONQuery, err := query.UnmarshalJSON(&msg.Body)
if err != nil {
......
......@@ -7,8 +7,8 @@ package consume
import (
"encoding/json"
"log"
"query-service/internal/entity"
"query-service/pkg/errorhandler"
)
/*
......@@ -28,7 +28,7 @@ func (s *Service) publishStatus(status string, sessionID *string, queryID *strin
msgBytes, err := json.Marshal(msg)
if err != nil {
errorhandler.FailWithError(err, "Marshalling status update message went wrong")
log.Printf("marshalling message failed: %e\n", err)
return
}
......
......@@ -19,15 +19,3 @@ func LogError(err error, msg string) {
fmt.Printf("%s: %v", msg, err)
}
}
/*
FailWithError panics if the error is not nil
err: error, the error being thrown
msg: string, the description of the error
*/
func FailWithError(err error, msg string) {
if err != nil {
fmt.Printf("%s: %v", msg, err)
panic(err)
}
}
......@@ -8,7 +8,6 @@ package logger
import (
"log"
"os"
"query-service/pkg/errorhandler"
"strconv"
)
......@@ -21,7 +20,7 @@ func Start() {
var err error
logMessages, err = strconv.ParseBool(os.Getenv("LOG_MESSAGES"))
if err != nil {
errorhandler.FailWithError(err, "invalid LOG_MESSAGES env variable")
log.Panic("LOG_MESSAGES variable not present")
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment