Skip to content

Commit

Permalink
Add EBICS server timeout exception
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-svirin committed Jan 21, 2025
1 parent 7eb818a commit ba980a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Exceptions/TimeoutEbicsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace EbicsApi\Ebics\Exceptions;

final class TimeoutEbicsException extends EbicsException
{
}
5 changes: 4 additions & 1 deletion src/Services/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace EbicsApi\Ebics\Services;

use EbicsApi\Ebics\Contracts\HttpClientInterface;
use EbicsApi\Ebics\Exceptions\TimeoutEbicsException;
use EbicsApi\Ebics\Models\Http\Request;
use EbicsApi\Ebics\Models\Http\Response;
use RuntimeException;
Expand All @@ -17,6 +18,7 @@ final class CurlHttpClient extends HttpClient implements HttpClientInterface
{
/**
* @inheritDoc
* @throws \EbicsApi\Ebics\Exceptions\TimeoutEbicsException
*/
public function post(string $url, Request $request): Response
{
Expand All @@ -35,14 +37,15 @@ public function post(string $url, Request $request): Response
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
$errorMsg = curl_error($ch);
}
curl_close($ch);

if (!is_string($contents)) {
throw new RuntimeException('Response is not a string. '. ($errorMsg ?? ''));
throw new TimeoutEbicsException('EBICS Bank response is not a string. Timeout is 400s. '. ($errorMsg ?? ''));
}

return $this->createResponse($contents);
Expand Down

0 comments on commit ba980a8

Please sign in to comment.