Skip to content

Commit 1c72bc7

Browse files
committed
feat: Add category unto ApplicationFailure;
Configure mapping
1 parent 6524496 commit 1c72bc7

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Exception/Failure/ApplicationErrorCategory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111

1212
namespace Temporal\Exception\Failure;
1313

14+
use Temporal\Api\Enums\V1\ApplicationErrorCategory as ProtoCategory;
15+
1416
/**
1517
* Used to categorize application failures, for example, to distinguish benign errors from others.
1618
*
1719
* @see \Temporal\Api\Enums\V1\ApplicationErrorCategory
1820
*/
19-
enum ApplicationErrorCategory
21+
enum ApplicationErrorCategory: int
2022
{
21-
case Unspecified;
23+
case Unspecified = ProtoCategory::APPLICATION_ERROR_CATEGORY_UNSPECIFIED;
2224

2325
/**
2426
* Expected application error with little/no severity.
2527
*/
26-
case Benign;
28+
case Benign = ProtoCategory::APPLICATION_ERROR_CATEGORY_BENIGN;
2729
}

src/Exception/Failure/ApplicationFailure.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ApplicationFailure extends TemporalFailure
4949
/**
5050
* @param ValuesInterface|null $details Optional details about the failure.
5151
* @param \DateInterval|null $nextRetryDelay Delay before the next retry attempt.
52+
* @param ApplicationErrorCategory $category The category of the application failure.
5253
*/
5354
public function __construct(
5455
string $message,
@@ -57,6 +58,7 @@ public function __construct(
5758
?ValuesInterface $details = null,
5859
?\Throwable $previous = null,
5960
private ?\DateInterval $nextRetryDelay = null,
61+
private readonly ApplicationErrorCategory $category = ApplicationErrorCategory::Unspecified,
6062
) {
6163
parent::__construct(
6264
self::buildMessage(\compact('message', 'type', 'nonRetryable')),
@@ -103,4 +105,9 @@ public function setNextRetryDelay(?\DateInterval $nextRetryDelay): void
103105
{
104106
$this->nextRetryDelay = $nextRetryDelay;
105107
}
108+
109+
public function getApplicationErrorCategory(): ApplicationErrorCategory
110+
{
111+
return $this->category;
112+
}
106113
}

src/Exception/Failure/FailureConverter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static function mapExceptionToFailure(\Throwable $e, DataConverterInterfa
7070
$info = new ApplicationFailureInfo();
7171
$info->setType($e->getType());
7272
$info->setNonRetryable($e->isNonRetryable());
73+
$info->setCategory($e->getApplicationErrorCategory()->value);
7374

7475
// Set Next Retry Delay
7576
$nextRetry = DateInterval::toDuration($e->getNextRetryDelay());
@@ -181,6 +182,7 @@ private static function createFailureException(Failure $failure, DataConverterIn
181182
$details,
182183
$previous,
183184
DateInterval::parseOrNull($info->getNextRetryDelay()),
185+
ApplicationErrorCategory::tryFrom($info->getCategory()) ?? ApplicationErrorCategory::Unspecified,
184186
);
185187

186188
case $failure->hasTimeoutFailureInfo():

0 commit comments

Comments
 (0)