Skip to content

Commit

Permalink
feat(packages/sui-decorators): add error reporter to tracer decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
javiauso committed Nov 6, 2024
1 parent 10e2ca9 commit 200da4e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/sui-decorators/src/decorators/tracer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const getReporter = () => {
return customReporter || new ConsoleReporter()
}

const getErrorReporter = () => {
const defaultErrorReporter = () => undefined
const customErrorReporter = isNode
? global.__SUI_DECORATOR_TRACER_ERROR_REPORTER__
: window.__SUI_DECORATOR_TRACER_ERROR_REPORTER__

return customErrorReporter || defaultErrorReporter
}

export default ({metric = null} = {}) => {
return (target, fnName, descriptor) => {
const {configurable, enumerable, writable} = descriptor
Expand Down Expand Up @@ -58,6 +67,9 @@ export default ({metric = null} = {}) => {
status: error ? statusCodes.FAIL : statusCodes.SUCCESS,
value: endTime - startTime
})
if (error) {
getErrorReporter()(error, metricName)
}
} else {
reporter.send({
metricName,
Expand All @@ -76,6 +88,7 @@ export default ({metric = null} = {}) => {
status: statusCodes.FAIL,
value: endTime - startTime
})
getErrorReporter()(error, metricName)

return Promise.reject(error)
})
Expand Down

0 comments on commit 200da4e

Please sign in to comment.