Skip to content

Commit 43812c4

Browse files
authored
Merge pull request #3111 from North-Two-Five/Node-ErrorHandling_#342
Update Node docs configuration to include new `errorhandler` property
2 parents 472d130 + e71c1b6 commit 43812c4

File tree

1 file changed

+24
-0
lines changed
  • src/connections/sources/catalog/libraries/server/node

1 file changed

+24
-0
lines changed

src/connections/sources/catalog/libraries/server/node/index.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,30 @@ var analytics = new Analytics('YOUR_WRITE_KEY', {
352352
</tr>
353353
</table>
354354

355+
### Error Handling
356+
357+
Additionally there is an optional `errorHandler` property available to the class constructor's options.
358+
If unspecified, the behaviour of the library does not change.
359+
If specified, when an axios request fails, `errorHandler(axiosError)` will be called instead of re-throwing the axios error.
360+
361+
Example usage:
362+
```javascript
363+
const Analytics = require('analytics-node');
364+
365+
const client = new Analytics('write key', {
366+
errorHandler: (err) => {
367+
console.error('analytics-node flush failed.')
368+
console.error(err)
369+
}
370+
});
371+
372+
client.track({
373+
event: 'event name',
374+
userId: 'user id'
375+
});
376+
377+
```
378+
If this fails when flushed no exception will be thrown, instead the axios error will be logged to the console.
355379

356380
## Development
357381

0 commit comments

Comments
 (0)