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/connections/functions/destination-functions.md
+25-2Lines changed: 25 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,11 +86,12 @@ To change which type of event the handler listens to, you can rename it to the n
86
86
87
87
A function's execution is considered successful if it finishes without any errors. You can also `throw` an error to indicate a failure on purpose. You can use these errors to validate event data before processing it, to ensure your function works as expected.
88
88
89
-
There are three pre-defined error types that you can `throw` to indicate that the function ran as expected, but that data could not be delivered:
89
+
You can `throw` the following pre-defined error types to indicate that the function ran as expected, but that data could not be delivered:
90
90
91
91
-`EventNotSupported`
92
92
-`InvalidEventPayload`
93
93
-`ValidationError`
94
+
-`RetryError`
94
95
95
96
The examples show basic uses of these error types.
96
97
@@ -110,6 +111,27 @@ async function onPage(event) {
110
111
asyncfunctiononAlias(event) {
111
112
thrownewEventNotSupported('Alias event is not supported')
112
113
}
114
+
115
+
asyncfunctiononTrack(event) {
116
+
let res
117
+
try {
118
+
res =awaitfetch('http://example-service.com/api', {
119
+
method:'POST',
120
+
headers: {
121
+
'Content-Type':'application/json'
122
+
},
123
+
body:JSON.stringify({ event })
124
+
})
125
+
} catch (err) {
126
+
// Retry on connection error
127
+
thrownewRetryError(err.message)
128
+
}
129
+
if (res.status>=500||res.status===429) {
130
+
// Retry on 5xx and 429s (ratelimits)
131
+
thrownewRetryError(`HTTP Status ${res.status}`)
132
+
}
133
+
}
134
+
113
135
```
114
136
If you do not supply a function for an event type, Segment throws an `EventNotSupported` error by default.
115
137
@@ -186,8 +208,9 @@ A function can throw errors, or Segment might encounter errors while invoking yo
186
208
-**Invalid Settings** - A configuration error prevented Segment from executing your code. If this error persists for more than an hour, [contact Segment Support](https://segment.com/help/contact/).
187
209
-**Message Rejected** - Your code threw `InvalidEventPayload` or `ValidationError` due to invalid input.
188
210
-**Unsupported Event Type** - Your code does not implement a specific event type (`onTrack()`, etc.) or threw a `EventNotSupported` error.
211
+
-**Retry** - Your code threw `RetryError` indicating that the function should be retried.
189
212
190
-
When these errors occur, Segment does not attempt to send that event to your destination function again.
213
+
Segment only attempts to send the event to your destination function again if a **Retry** error occurs.
Copy file name to clipboardExpand all lines: src/connections/functions/source-functions.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -350,8 +350,9 @@ async function onRequest(request, settings) {
350
350
-**Invalid Settings**: A configuration error prevented Segment from executing your code. If this error persists for more than an hour, [contact Segment Support](https://segment.com/help/contact/).
351
351
-**Message Rejected**: Your code threw `InvalidEventPayload` or `ValidationError` due to invalid input.
352
352
-**Unsupported Event Type**: Your code does not implement a specific event type (`onTrack()`, etc.) or threw a `EventNotSupported` error.
353
+
-**Retry** - Your code threw `RetryError` indicating that the function should be retried.
353
354
354
-
These errors are not retried.
355
+
Segment only attempts to run your source function again if a **Retry** error occurs.
0 commit comments