-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathCustomExceptionPropertiesOrchestration.java
More file actions
62 lines (52 loc) · 2.13 KB
/
Copy pathCustomExceptionPropertiesOrchestration.java
File metadata and controls
62 lines (52 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.function;
import com.microsoft.azure.functions.annotation.*;
import com.function.exceptions.BusinessValidationException;
import com.microsoft.azure.functions.*;
import java.time.Instant;
import java.util.*;
import com.microsoft.durabletask.*;
import com.microsoft.durabletask.azurefunctions.DurableActivityTrigger;
import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger;
/**
* Azure Functions with Durable Task for custom exception properties in failure details.
*/
public class CustomExceptionPropertiesOrchestration {
/**
* Orchestrator: OrchestrationWithCustomException
* Calls BusinessActivity and catches TaskFailedException, returning the FailureDetails.
*/
@FunctionName("OrchestrationWithCustomException")
public FailureDetails orchestrationWithCustomException(
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) {
try {
ctx.callActivity("BusinessActivity", null, Void.class).await();
} catch (TaskFailedException ex) {
return ex.getErrorDetails();
}
// Should never reach here.
return null;
}
/**
* Activity: BusinessActivity
* Throws a BusinessValidationException with custom properties.
*/
@FunctionName("BusinessActivity")
public void businessActivity(
@DurableActivityTrigger(name = "input") String input,
final ExecutionContext context) throws BusinessValidationException {
Map<String, Object> dictionaryProperty = new LinkedHashMap<>();
dictionaryProperty.put("error_code", "VALIDATION_FAILED");
dictionaryProperty.put("retry_count", 3);
dictionaryProperty.put("is_critical", true);
List<Object> listProperty = Arrays.asList("error1", "error2", 500, null);
throw new BusinessValidationException(
"Business logic validation failed",
"validation-error-123",
100,
999999999L,
Instant.parse("2025-10-15T14:30:00Z"),
dictionaryProperty,
listProperty,
null);
}
}