@@ -449,7 +449,23 @@ private function signWrapper(JSignPDF $jSignPDF): string {
449449 $ jSignPDF ->setParam ($ param );
450450 return $ jSignPDF ->sign ();
451451 } catch (\Throwable $ th ) {
452- $ rows = str_getcsv ($ th ->getMessage ());
452+ $ errorMessage = $ th ->getMessage ();
453+ $ rows = str_getcsv ($ errorMessage );
454+
455+ $ tsaError = array_filter ($ rows , fn ($ r ) => str_contains ((string )$ r , 'Invalid TSA ' ));
456+ if (!empty ($ tsaError )) {
457+ $ tsaErrorMsg = current ($ tsaError );
458+ if (preg_match ("/Invalid TSA '([^']+)'/ " , $ tsaErrorMsg , $ matches )) {
459+ $ friendlyMessage = 'Timestamp Authority (TSA) service is unavailable or misconfigured. ' . "\n"
460+ . 'Please check the TSA configuration. ' ;
461+ } else {
462+ $ friendlyMessage = 'Timestamp Authority (TSA) service error. ' . "\n"
463+ . 'Please check the TSA configuration. ' ;
464+ }
465+ throw new LibresignException ($ friendlyMessage );
466+ }
467+
468+ // Check for hash algorithm errors
453469 $ hashAlgorithm = array_filter ($ rows , fn ($ r ) => str_contains ((string )$ r , 'The chosen hash algorithm ' ));
454470 if (!empty ($ hashAlgorithm )) {
455471 $ hashAlgorithm = current ($ hashAlgorithm );
@@ -458,8 +474,9 @@ private function signWrapper(JSignPDF $jSignPDF): string {
458474 $ hashAlgorithm = preg_replace ('/\.( )/ ' , ". \n" , $ hashAlgorithm );
459475 throw new LibresignException ($ hashAlgorithm );
460476 }
461- $ this ->logger ->error ('Error at JSignPdf side. LibreSign can not do nothing. Follow the error message: ' . $ th ->getMessage ());
462- throw new \Exception ($ th ->getMessage ());
477+
478+ $ this ->logger ->error ('Error at JSignPdf side. LibreSign can not do nothing. Follow the error message: ' . $ errorMessage );
479+ throw new \Exception ($ errorMessage );
463480 }
464481 }
465482}
0 commit comments