Skip to content

Commit e9e53ed

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

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
@@ -452,7 +452,23 @@ private function signWrapper(JSignPDF $jSignPDF): string {
452452
$jSignPDF->setParam($param);
453453
return $jSignPDF->sign();
454454
} catch (\Throwable $th) {
455-
$rows = str_getcsv($th->getMessage());
455+
$errorMessage = $th->getMessage();
456+
$rows = str_getcsv($errorMessage);
457+
458+
$tsaError = array_filter($rows, fn ($r) => str_contains((string)$r, 'Invalid TSA'));
459+
if (!empty($tsaError)) {
460+
$tsaErrorMsg = current($tsaError);
461+
if (preg_match("/Invalid TSA '([^']+)'/", $tsaErrorMsg, $matches)) {
462+
$friendlyMessage = 'Timestamp Authority (TSA) service is unavailable or misconfigured.' . "\n"
463+
. 'Please check the TSA configuration.';
464+
} else {
465+
$friendlyMessage = 'Timestamp Authority (TSA) service error.' . "\n"
466+
. 'Please check the TSA configuration.';
467+
}
468+
throw new LibresignException($friendlyMessage);
469+
}
470+
471+
// Check for hash algorithm errors
456472
$hashAlgorithm = array_filter($rows, fn ($r) => str_contains((string)$r, 'The chosen hash algorithm'));
457473
if (!empty($hashAlgorithm)) {
458474
$hashAlgorithm = current($hashAlgorithm);
@@ -461,8 +477,9 @@ private function signWrapper(JSignPDF $jSignPDF): string {
461477
$hashAlgorithm = preg_replace('/\.( )/', ".\n", $hashAlgorithm);
462478
throw new LibresignException($hashAlgorithm);
463479
}
464-
$this->logger->error('Error at JSignPdf side. LibreSign can not do nothing. Follow the error message: ' . $th->getMessage());
465-
throw new \Exception($th->getMessage());
480+
481+
$this->logger->error('Error at JSignPdf side. LibreSign can not do nothing. Follow the error message: ' . $errorMessage);
482+
throw new \Exception($errorMessage);
466483
}
467484
}
468485
}

0 commit comments

Comments
 (0)