Skip to content

Commit

Permalink
feat: throw relevant error when no pdfs are received (#516)
Browse files Browse the repository at this point in the history
INT-787
  • Loading branch information
joerivanveen authored Jan 2, 2025
1 parent 8357c71 commit 35ac23a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use BadMethodCallException;
use Closure;
use GuzzleHttp\Exception\BadResponseException;
use InvalidArgumentException;
use MyParcelNL\Sdk\src\Adapter\ConsignmentAdapter;
use MyParcelNL\Sdk\src\Concerns\HasUserAgent;
Expand Down Expand Up @@ -467,7 +468,20 @@ public function setPdfOfLabels($positions = self::DEFAULT_A4_POSITION): self
)
->sendRequest('GET', MyParcelRequest::REQUEST_TYPE_RETRIEVE_LABEL);

$this->label_pdf = $request->getResult();
/**
* When account needs to pay upfront, an array is returned with payment information,
* instead of the actual pdf’s. It will throw an unintelligible error when not handled here.
*/
$result = $request->getResult();

if (!is_string($result) || !preg_match('/^%PDF-1./', $result)) {
if (is_array($result) && isset($result['data']['payment_instructions'])) {
throw new ApiException('Received payment link instead of pdf. Check your MyParcel account status.');
}
throw new ApiException('Did not receive expected pdf response. Please contact MyParcel.');
}

$this->label_pdf = $result;
}

$this->setLatestData();
Expand Down

0 comments on commit 35ac23a

Please sign in to comment.