Skip to content

Commit

Permalink
Improved NATS error metric
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonst committed Oct 10, 2023
1 parent f4175b2 commit bfc811e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulms/api-clients",
"version": "6.6.0",
"version": "6.6.1",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
19 changes: 17 additions & 2 deletions src/nats-client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* eslint-disable unicorn/no-abusive-eslint-disable, unicorn/numeric-separators-style */
/* global window */
import { connect, jwtAuthenticator, JSONCodec } from 'nats.ws/lib/src/mod'
import {
JSONCodec,
NatsError,
connect,
jwtAuthenticator,
} from 'nats.ws/lib/src/mod'

const jsonCodec = JSONCodec()

Expand Down Expand Up @@ -173,7 +178,17 @@ class NATSClient {
} catch (error) {
if (this.trackError) this.trackError(error)
if (this.trackEvent) {
this.trackEvent('Debug', 'NATS.Error', 'v1', undefined, { error })
let errorMeta = error

if (error instanceof NatsError) {
const { code, message, name: errorName } = error

errorMeta = { code, message, name: errorName }
}

this.trackEvent('Debug', 'NATS.Error', 'v1', undefined, {
error: errorMeta,
})
}

console.log('[NATS] Error connecting to server:', error) // eslint-disable-line no-console
Expand Down

0 comments on commit bfc811e

Please sign in to comment.