Skip to content

Commit 1bb2edf

Browse files
committed
Update function docs for RetryError
1 parent e6e105e commit 1bb2edf

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/connections/functions/destination-functions.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ To change which type of event the handler listens to, you can rename it to the n
8686

8787
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.
8888

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+
There are four pre-defined error types that you can `throw` to indicate that the function ran as expected, but that data could not be delivered:
9090

9191
- `EventNotSupported`
9292
- `InvalidEventPayload`
9393
- `ValidationError`
94+
- `RetryError`
9495

9596
The examples show basic uses of these error types.
9697

@@ -110,6 +111,20 @@ async function onPage(event) {
110111
async function onAlias(event) {
111112
throw new EventNotSupported('Alias event is not supported')
112113
}
114+
115+
async function onTrack(event) {
116+
try {
117+
await fetch('http://example-service.com/api', {
118+
method: 'POST',
119+
headers: {
120+
'Content-Type': 'application/json'
121+
}
122+
body: JSON.stringify({ event })
123+
})
124+
} catch (err) {
125+
throw new RetryError(err.message)
126+
}
127+
}
113128
```
114129
If you do not supply a function for an event type, Segment throws an `EventNotSupported` error by default.
115130

@@ -186,8 +201,9 @@ A function can throw errors, or Segment might encounter errors while invoking yo
186201
- **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/).
187202
- **Message Rejected** - Your code threw `InvalidEventPayload` or `ValidationError` due to invalid input.
188203
- **Unsupported Event Type** - Your code does not implement a specific event type (`onTrack()`, etc.) or threw a `EventNotSupported` error.
204+
- **Retry** - Your code threw `RetryError` indicating that the function should be retried.
189205

190-
When these errors occur, Segment does not attempt to send that event to your destination function again.
206+
Segment only attempts to send the event to your destination function again if a **Retry** error occurs.
191207

192208
### Destination functions logs
193209

src/connections/functions/source-functions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ async function onRequest(request, settings) {
350350
- **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/).
351351
- **Message Rejected**: Your code threw `InvalidEventPayload` or `ValidationError` due to invalid input.
352352
- **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.
353354

354-
These errors are not retried.
355+
Segment only attempts to run your source function again if a **Retry** error occurs.
355356

356357
## Managing source functions
357358

0 commit comments

Comments
 (0)