Skip to content

Commit

Permalink
Merge pull request #10 from picqer/throw-rate-limit-order-not-found-e…
Browse files Browse the repository at this point in the history
…xception-accordingly

Throw OrderNotFound/RateLimitException if client does not give ClientException but request not successful
  • Loading branch information
annajeanine authored Jul 24, 2020
2 parents 357c480 + 0f5cd40 commit 9ebc512
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static function get(string $id): ?Order
static::handleException($e);
}

self::throwExceptionIfNotSuccessfull($response);

return new Order(json_decode((string) $response->getBody(), true));
}

Expand Down Expand Up @@ -101,4 +103,21 @@ private static function handleException(ClientException $e): void

throw $e;
}

private static function throwExceptionIfNotSuccessfull($response)
{
if ($response->getStatusCode() === 404) {
throw new OrderNotFoundException(
json_decode((string) $response->getBody(), true),
404
);
}

if ($response->getStatusCode() === 429) {
throw new RateLimitException(
json_decode((string) $response->getBody(), true),
429
);
}
}
}

0 comments on commit 9ebc512

Please sign in to comment.