@@ -37,6 +37,7 @@ public function notifySuccess($request, $submission)
3737
3838 public function notifyError ($ request , $ submission , $ error )
3939 {
40+ $ error = $ this ->normalizeError ($ error );
4041 error_log ("Failed to send the request to Thoth: {$ error }" );
4142 $ this ->notify (
4243 $ request ,
@@ -62,6 +63,7 @@ public function notify($request, $submission, $notificationType, $messageKey, $e
6263
6364 public function logInfo ($ request , $ submission , $ messageKey , $ error = null )
6465 {
66+ $ error = $ this ->normalizeError ($ error );
6567 $ currentUser = $ request ->getUser ();
6668 $ eventLog = Repo::eventLog ()->newDataObject ([
6769 'assocType ' => Application::ASSOC_TYPE_SUBMISSION ,
@@ -76,6 +78,23 @@ public function logInfo($request, $submission, $messageKey, $error = null)
7678 Repo::eventLog ()->add ($ eventLog );
7779 }
7880
81+ protected function normalizeError ($ error )
82+ {
83+ if ($ error === null || is_scalar ($ error )) {
84+ return $ error ;
85+ }
86+
87+ if ($ error instanceof \Throwable) {
88+ return $ error ->getMessage ();
89+ }
90+
91+ if (is_object ($ error ) && method_exists ($ error , 'getMessage ' )) {
92+ return $ error ->getMessage ();
93+ }
94+
95+ return json_encode ($ error );
96+ }
97+
7998 public function addJavaScriptData ($ request , $ templateMgr )
8099 {
81100 $ data = ['notificationUrl ' => $ request ->url (null , 'notification ' , 'fetchNotification ' )];
0 commit comments