Skip to content

Commit 685d91c

Browse files
committed
fix: handle error about TSA
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 4ebe7ee commit 685d91c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lib/Handler/SignEngine/JSignPdfHandler.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)