Skip to content

Commit e71c1b6

Browse files
committed
Update Node docs configuration to include new errorhandler property
1 parent b04e709 commit e71c1b6

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
@@ -350,6 +350,30 @@ var analytics = new Analytics('YOUR_WRITE_KEY', {
350350
</tr>
351351
</table>
352352

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

354378
## Development
355379

0 commit comments

Comments
 (0)