Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ApplicantSessions/ApplicantSessionsApiImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ public function uploadDocument(DocumentType $documentType, string $sessionToken,
]
);
} catch (RequestException $exception) {
if ($exception->getResponse()->getStatusCode() === 422) {
if (in_array($exception->getResponse()->getStatusCode(), [422, 400])) {
$error = psr_response_to_json($exception->getResponse());
$errorMessage = $error['error'] ?? 'Failed to upload document.';
$failedChecks = $error['failedChecks'] ?? [];
$filename = basename($filePath);

throw new SnapptDocumentUploadException($filename, $errorMessage);
throw new SnapptDocumentUploadException($filename, $failedChecks, $errorMessage);
}

throw $exception;
Expand Down
14 changes: 13 additions & 1 deletion src/Exceptions/SnapptDocumentUploadException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

class SnapptDocumentUploadException extends Exception
{
/**
* @param list<string> $failedChecks
*/
public function __construct(
private readonly string $snapptFilename,
string $message
private readonly array $failedChecks,
string $message,
) {
parent::__construct($message);
}
Expand All @@ -17,4 +21,12 @@ public function getSnapptFilename(): string
{
return $this->snapptFilename;
}

/**
* @return list<string>
*/
public function getFailedChecks(): array
{
return $this->failedChecks;
}
}
2 changes: 1 addition & 1 deletion src/Fake/FakeApplicantSessionsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function uploadDocument(DocumentType $documentType, string $sessionToken,
$applicantEmail = Arr::get($this->cache->get("{$sessionToken}:applicant:session"), 'email', '');

if (Str::contains($applicantEmail, 'snappt_fail_documents')) {
throw new SnapptDocumentUploadException(basename($filePath), 'This PDF appears to be a print-to-PDF. Please download an original PDF from your bank or financial institution.');
throw new SnapptDocumentUploadException(basename($filePath), [], 'This PDF appears to be a print-to-PDF. Please download an original PDF from your bank or financial institution.');
}

$id = Arr::get($this->cache->get("{$sessionToken}:applicant:session"), 'id');
Expand Down