Skip to content

Commit 6fe5ec6

Browse files
authored
Merge pull request #5 from php-etl/feature/rejection
return rejection when there is a network error
2 parents 1388f34 + bfdf02c commit 6fe5ec6

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

src/CustomerExtractor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Kiboko\Component\Bucket\RejectionResultBucket;
99
use Kiboko\Contract\Bucket\ResultBucketInterface;
1010
use Kiboko\Contract\Pipeline\ExtractorInterface;
11+
use Psr\Http\Client\NetworkExceptionInterface;
1112

1213
final class CustomerExtractor implements ExtractorInterface
1314
{
@@ -62,8 +63,15 @@ public function extract(): iterable
6263

6364
yield $this->processResponse($response);
6465
}
65-
} catch (\Exception $exception) {
66+
} catch (NetworkExceptionInterface $exception) {
6667
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
68+
yield new RejectionResultBucket([
69+
'path' => 'customer',
70+
'method' => 'get',
71+
'queryParameters' => $this->compileQueryParameters(),
72+
]);
73+
} catch (\Exception $exception) {
74+
$this->logger->critical($exception->getMessage(), ['exception' => $exception]);
6775
}
6876
}
6977

src/InvoiceExtractor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Kiboko\Component\Bucket\RejectionResultBucket;
99
use Kiboko\Contract\Bucket\ResultBucketInterface;
1010
use Kiboko\Contract\Pipeline\ExtractorInterface;
11+
use Psr\Http\Client\NetworkExceptionInterface;
1112

1213
final class InvoiceExtractor implements ExtractorInterface
1314
{
@@ -62,8 +63,15 @@ public function extract(): iterable
6263

6364
yield $this->processResponse($response);
6465
}
65-
} catch (\Exception $exception) {
66+
} catch (NetworkExceptionInterface $exception) {
6667
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
68+
yield new RejectionResultBucket([
69+
'path' => 'invoice',
70+
'method' => 'get',
71+
'queryParameters' => $this->compileQueryParameters(),
72+
]);
73+
} catch (\Exception $exception) {
74+
$this->logger->critical($exception->getMessage(), ['exception' => $exception]);
6775
}
6876
}
6977

src/OrderExtractor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Kiboko\Component\Bucket\RejectionResultBucket;
99
use Kiboko\Contract\Bucket\ResultBucketInterface;
1010
use Kiboko\Contract\Pipeline\ExtractorInterface;
11+
use Psr\Http\Client\NetworkExceptionInterface;
1112

1213
final class OrderExtractor implements ExtractorInterface
1314
{
@@ -62,8 +63,15 @@ public function extract(): iterable
6263

6364
yield $this->processResponse($response);
6465
}
65-
} catch (\Exception $exception) {
66+
} catch (NetworkExceptionInterface $exception) {
6667
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
68+
yield new RejectionResultBucket([
69+
'path' => 'order',
70+
'method' => 'get',
71+
'queryParameters' => $this->compileQueryParameters(),
72+
]);
73+
} catch (\Exception $exception) {
74+
$this->logger->critical($exception->getMessage(), ['exception' => $exception]);
6775
}
6876
}
6977

src/ProductExtractor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Kiboko\Component\Bucket\RejectionResultBucket;
99
use Kiboko\Contract\Bucket\ResultBucketInterface;
1010
use Kiboko\Contract\Pipeline\ExtractorInterface;
11+
use Psr\Http\Client\NetworkExceptionInterface;
1112

1213
final class ProductExtractor implements ExtractorInterface
1314
{
@@ -62,8 +63,15 @@ public function extract(): iterable
6263

6364
yield $this->processResponse($response);
6465
}
65-
} catch (\Exception $exception) {
66+
} catch (NetworkExceptionInterface $exception) {
6667
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
68+
yield new RejectionResultBucket([
69+
'path' => 'product',
70+
'method' => 'get',
71+
'queryParameters' => $this->compileQueryParameters(),
72+
]);
73+
} catch (\Exception $exception) {
74+
$this->logger->critical($exception->getMessage(), ['exception' => $exception]);
6775
}
6876
}
6977

0 commit comments

Comments
 (0)