You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/_includes/content/functions/errors-and-error-handling.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
<!-- Use for destination and insert functions -->
1
+
<!-- Use for destination functions -->
2
2
3
3
Segment considers a function's execution successful if it finishes without error. You can also `throw` an error to create a failure on purpose. Use these errors to validate event data before processing it, to ensure the function works as expected.
Copy file name to clipboardExpand all lines: src/connections/functions/index.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -35,10 +35,10 @@ Learn more about [destination functions](/docs/connections/functions/destination
35
35
#### Destination insert functions
36
36
Destination insert functions help you enrich your data with code before you send it to downstream destinations.
37
37
38
-
> info "Destination Insert Functions in Private Beta"
39
-
> Destination Insert Functions is in Private Beta, and Segment is actively working on this feature. Some functionality may change before it becomes generally available. [Contact Segment](https://segment.com/help/contact/){:target="_blank"} with any feedback or questions.
38
+
> info "Destination Insert Functions in Public Beta"
39
+
> Destination Insert Functions is in Public Beta, and Segment is actively working on this feature. Some functionality may change before it becomes generally available. [Contact Segment](https://segment.com/help/contact/){:target="_blank"} with any feedback or questions.
40
40
41
-
Use cases:
41
+
Use cases:
42
42
- Implement custom logic and enrich data with third party sources
43
43
- Transform outgoing data with advanced filtration and computation
44
44
- Ensure data compliance by performing tokenisation, encryption, or decryption before sending data downstream
Copy file name to clipboardExpand all lines: src/connections/functions/insert-functions.md
+59-3Lines changed: 59 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,8 @@ Use Destination Insert Functions to enrich, transform, or filter your data befor
14
14
15
15
**Customize filtration for your destinations**: Create custom logic with nested if-else statements, regex, custom business rules, and more to filter event data.
16
16
17
-
> info "Destination Insert Functions in Private Beta"
18
-
> Destination Insert Functions is in Private Beta, and Segment is actively working on this feature. Some functionality may change before it becomes generally available. [Contact Segment](https://segment.com/help/contact/){:target="_blank"} with any feedback or questions.
17
+
> info "Destination Insert Functions in Public Beta"
18
+
> Destination Insert Functions is in Public Beta, and Segment is actively working on this feature. Some functionality may change before it becomes generally available. [Contact Segment](https://segment.com/help/contact/){:target="_blank"} with any feedback or questions.
19
19
20
20
21
21
## Create destination insert functions
@@ -91,6 +91,9 @@ async function onTrack(event) {
91
91
timestamp:event.timestamp
92
92
})
93
93
})
94
+
95
+
returnevent;
96
+
94
97
}
95
98
```
96
99
@@ -101,7 +104,60 @@ To change which event type the handler listens to, you can rename it to the name
101
104
102
105
### Errors and error handling
103
106
104
-
{% include content/functions/errors-and-error-handling.md %}
107
+
Segment considers a function's execution successful if it finishes without error. You can `throw` an error to create a failure on purpose. Use these errors to validate event data before processing it to ensure the function works as expected.
108
+
109
+
You can `throw` the following pre-defined error types to indicate that the function ran as expected, but the data was not deliverable:
110
+
111
+
-`EventNotSupported`
112
+
-`InvalidEventPayload`
113
+
-`ValidationError`
114
+
-`RetryError`
115
+
116
+
The examples show basic uses of these error types.
117
+
118
+
```js
119
+
asyncfunctiononGroup(event) {
120
+
if (!event.traits.company) {
121
+
thrownewInvalidEventPayload('Company name is required')
122
+
}
123
+
}
124
+
125
+
asyncfunctiononPage(event) {
126
+
if (!event.properties.pageName) {
127
+
thrownewValidationError('Page name is required')
128
+
}
129
+
}
130
+
131
+
asyncfunctiononAlias(event) {
132
+
thrownewEventNotSupported('Alias event is not supported')
133
+
}
134
+
135
+
asyncfunctiononTrack(event) {
136
+
let res
137
+
try {
138
+
res =awaitfetch('http://example-service.com/api', {
139
+
method:'POST',
140
+
headers: {
141
+
'Content-Type':'application/json'
142
+
},
143
+
body:JSON.stringify({ event })
144
+
})
145
+
146
+
returnevent;
147
+
148
+
} catch (err) {
149
+
// Retry on connection error
150
+
thrownewRetryError(err.message)
151
+
}
152
+
if (res.status>=500||res.status===429) {
153
+
// Retry on 5xx and 429s (ratelimits)
154
+
thrownewRetryError(`HTTP Status ${res.status}`)
155
+
}
156
+
}
157
+
158
+
```
159
+
If you don't supply a function for an event type, Segment throws an `EventNotSupported` error by default.
160
+
105
161
106
162
You can read more about [error handling](#destination-insert-functions-logs-and-errors) below.
0 commit comments