Skip to content

Commit 74fdeb0

Browse files
committed
fix: Add clearer error message for multi-page PDF uploads
AWS Textract synchronous API only supports single-page PDFs. Multi-page PDFs require async processing via S3. Detects 'UnsupportedDocumentException' and provides user-friendly message instead of generic 'unsupported document format' error.
1 parent ef29570 commit 74fdeb0

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

  • cloudformation/scenarios/localgov-drupal/drupal/web/modules/custom/ndx_aws_ai/src/Service

cloudformation/scenarios/localgov-drupal/drupal/web/modules/custom/ndx_aws_ai/src/Service/TextractService.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ protected function invokeAnalyzeDocument(string $documentData, array $featureTyp
435435
catch (AwsException $e) {
436436
$lastException = $e;
437437
$errorCode = $e->getAwsErrorCode() ?? 'UnknownError';
438+
$errorMessage = $e->getAwsErrorMessage() ?? '';
439+
440+
// Check for multi-page PDF error (sync API only supports single-page).
441+
if ($errorCode === 'UnsupportedDocumentException' &&
442+
stripos($errorMessage, 'unsupported document format') !== FALSE) {
443+
throw new \InvalidArgumentException(
444+
'This PDF has multiple pages. The synchronous API only supports single-page PDFs. ' .
445+
'Please upload a single-page PDF or use a shorter document.'
446+
);
447+
}
438448

439449
if ($this->rateLimiter->isRetryable($errorCode) && $attempt < $this->rateLimiter->getMaxRetries() - 1) {
440450
$this->errorHandler->logRetry('Textract', 'analyzeDocument', $attempt + 1, $errorCode);

0 commit comments

Comments
 (0)