@@ -22,6 +22,7 @@ public function notifySuccess($request, $submission)
2222
2323 public function notifyError ($ request , $ submission , $ error )
2424 {
25+ $ error = $ this ->normalizeError ($ error );
2526 error_log ("Failed to send the request to Thoth: {$ error }" );
2627 $ this ->notify (
2728 $ request ,
@@ -47,6 +48,7 @@ public function notify($request, $submission, $notificationType, $messageKey, $e
4748
4849 public function logInfo ($ request , $ submission , $ messageKey , $ error = null )
4950 {
51+ $ error = $ this ->normalizeError ($ error );
5052 import ('lib.pkp.classes.log.SubmissionLog ' );
5153 import ('classes.log.SubmissionEventLogEntry ' );
5254 SubmissionLog::logEvent (
@@ -58,6 +60,23 @@ public function logInfo($request, $submission, $messageKey, $error = null)
5860 );
5961 }
6062
63+ protected function normalizeError ($ error )
64+ {
65+ if ($ error === null || is_scalar ($ error )) {
66+ return $ error ;
67+ }
68+
69+ if ($ error instanceof Throwable) {
70+ return $ error ->getMessage ();
71+ }
72+
73+ if (is_object ($ error ) && method_exists ($ error , 'getMessage ' )) {
74+ return $ error ->getMessage ();
75+ }
76+
77+ return json_encode ($ error );
78+ }
79+
6180 public function addJavaScriptData ($ request , $ templateMgr )
6281 {
6382 $ data = ['notificationUrl ' => $ request ->url (null , 'notification ' , 'fetchNotification ' )];
0 commit comments