From 0519da16b22efcd8daac4151ef9860595b78e045 Mon Sep 17 00:00:00 2001
From: Johan de Klerk <johan@shiplogic.com>
Date: Mon, 8 Apr 2024 11:14:06 +0200
Subject: [PATCH] Check for error type

---
 api_responses/api_responses.go | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/api_responses/api_responses.go b/api_responses/api_responses.go
index 2138361..0f63255 100644
--- a/api_responses/api_responses.go
+++ b/api_responses/api_responses.go
@@ -274,8 +274,13 @@ func GenericJSONResponseWithMessage(code int, err error) events.APIGatewayProxyR
 	var body map[string]string
 
 	if err != nil {
-		customErr := err.(*errors.CustomError)
-		message = customErr.Formatted(errors.FormattingOptions{NewLines: false, Causes: true})
+		var message string
+		if customErr, ok := err.(*errors.CustomError); ok {
+			message = customErr.Formatted(errors.FormattingOptions{NewLines: false, Causes: true})
+		} else {
+			message = err.Error()
+		}
+
 		body = map[string]string{
 			"message": string_utils.Capitalize(message),
 		}
-- 
GitLab