Skip to content

Commit

Permalink
Merge pull request #1860 from SUI-Components/feat-error-reporter-trac…
Browse files Browse the repository at this point in the history
…er-decorator

feat(packages/sui-decorators): add error reporter to tracer decorator
  • Loading branch information
javiauso authored Nov 7, 2024
2 parents 74cf143 + 200da4e commit 32f4965
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 32f4965

Please sign in to comment.