@@ -28,6 +28,7 @@ public function notifySuccess($request, $submission)
2828
2929 public function notifyError ($ request , $ submission , $ error )
3030 {
31+ $ error = $ this ->normalizeError ($ error );
3132 error_log ("Failed to send the request to Thoth: {$ error }" );
3233 $ this ->notify (
3334 $ request ,
@@ -53,6 +54,7 @@ public function notify($request, $submission, $notificationType, $messageKey, $e
5354
5455 public function logInfo ($ request , $ submission , $ messageKey , $ error = null )
5556 {
57+ $ error = $ this ->normalizeError ($ error );
5658 $ currentUser = $ request ->getUser ();
5759 $ eventLog = Repo::eventLog ()->newDataObject ([
5860 'assocType ' => Application::ASSOC_TYPE_SUBMISSION ,
@@ -67,6 +69,23 @@ public function logInfo($request, $submission, $messageKey, $error = null)
6769 Repo::eventLog ()->add ($ eventLog );
6870 }
6971
72+ protected function normalizeError ($ error )
73+ {
74+ if ($ error === null || is_scalar ($ error )) {
75+ return $ error ;
76+ }
77+
78+ if ($ error instanceof Throwable) {
79+ return $ error ->getMessage ();
80+ }
81+
82+ if (is_object ($ error ) && method_exists ($ error , 'getMessage ' )) {
83+ return $ error ->getMessage ();
84+ }
85+
86+ return json_encode ($ error );
87+ }
88+
7089 public function addJavaScriptData ($ request , $ templateMgr )
7190 {
7291 $ data = ['notificationUrl ' => $ request ->url (null , 'notification ' , 'fetchNotification ' )];
0 commit comments