Skip to content

Commit

Permalink
refactor(packages/sui-logger): add missed Trackers in client and serv…
Browse files Browse the repository at this point in the history
…er level
  • Loading branch information
nucliweb committed Oct 15, 2024
1 parent 2b96994 commit 4106c99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/sui-logger/src/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import createLogger from './logger'

export const createClientLogger = ({userId, trackerName} = {}) =>
export const createClientLogger = ({Trackers, userId, trackerName} = {}) =>
createLogger({
Trackers,
listenUnhandled: logError => {
const handleWindowError = e => {
const error = e.reason || e.error
Expand Down
3 changes: 2 additions & 1 deletion packages/sui-logger/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const extractFrom = req => {
}
}

export const logErrorsMiddleware = (error, req, res, next) => {
export const logErrorsMiddleware = (Trackers, error, req, res, next) => {
const logger = createLogger({
Trackers,
...extractFrom(req),
forwardConsoleErrors: false
})
Expand Down
7 changes: 6 additions & 1 deletion packages/sui-logger/test/server/indexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,27 @@ describe('initTracker', () => {
describe('logsErrorsMiddleware', () => {
let logger
let loggerPkgStub
let trackerStub
let TrackersCreateStub

before(() => {
logger = {error: sinon.stub()}
loggerPkgStub = sinon.stub(loggerPkg, 'default').returns(logger)
trackerStub = {emit: sinon.stub()}
TrackersCreateStub = sinon.stub(Trackers, 'create').returns(trackerStub)
})

after(() => {
loggerPkgStub.restore()
TrackersCreateStub.restore()
})

it('log the error and pass execution to next middleware', () => {
const error = 'Error Message'
const req = {headers: {}, url: '/'}
const res = null
const next = sinon.stub()
server.logErrorsMiddleware(error, req, res, next)
server.logErrorsMiddleware(trackerStub, error, req, res, next)

expect(logger.error.calledWith(error)).to.equal(true)
expect(next.calledWith(error)).to.equal(true)
Expand Down

0 comments on commit 4106c99

Please sign in to comment.