Skip to content

Commit

Permalink
reduce number of calls to _clientContext.getStore()
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerbenw committed Aug 29, 2024
1 parent fc02f00 commit c06b16b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/node/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ Object.keys(Client.prototype).forEach((m) => {
Bugsnag[m] = function () {
// if we are in an async context, use the client from that context
let client = Bugsnag._client
if (client && client._clientContext && client._clientContext.getStore()) {
client = client._clientContext.getStore()
const ctx = client && client._clientContext && client._clientContext.getStore()
if (ctx) {
client = ctx
}

if (!client) return console.error(`Bugsnag.${m}() was called before Bugsnag.start()`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
if (!client._config.enabledErrorTypes.unhandledExceptions) return
_handler = err => {
// if we are in an async context, use the client from that context
const c = (client._clientContext && client._clientContext.getStore()) ? client._clientContext.getStore() : client
const ctx = client._clientContext && client._clientContext.getStore()
const c = ctx || client

// check if the stacktrace has no context, if so append the frames we created earlier
// see plugin-contextualize for where this is created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
if (!client._config.autoDetectErrors || !client._config.enabledErrorTypes.unhandledRejections) return
_handler = err => {
// if we are in an async context, use the client from that context
const c = (client._clientContext && client._clientContext.getStore()) ? client._clientContext.getStore() : client
const ctx = client._clientContext && client._clientContext.getStore()
const c = ctx || client

const event = c.Event.create(err, false, {
severity: 'error',
Expand Down

0 comments on commit c06b16b

Please sign in to comment.