Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0.3] Export captureError from root. #32

Open
prescience-data opened this issue Mar 19, 2022 · 1 comment
Open

[2.0.3] Export captureError from root. #32

prescience-data opened this issue Mar 19, 2022 · 1 comment

Comments

@prescience-data
Copy link

prescience-data commented Mar 19, 2022

In v1.x.x I was able to (albeit indirectly) access captureError which was really useful when I just needed to pipe an error directly from a catch without a lot dealing with the full logger.

I previously was destructuring this from the instantiated root logger (https://github.com/logdna/logdna-browser/blob/v1.1.4/src/index.ts#L165) but as far as I can tell there is no direct access anymore via the root methods export (https://github.com/logdna/logdna-browser/blob/v2.0.3/src/LogDNAMethods.ts)

It would be awesome to get access to https://github.com/logdna/logdna-browser/blob/v2.0.3/src/capture.ts#L34 from the root index exports.

// index.ts

import { LogDNAMethods } from './LogDNAMethods';

import { init, config, methods } from './init';
import plugins from './plugins';
import { addContext } from './context-manager';
import { setSessionId } from './session-manager';
import { captureError } from './capture';

// ...

export { captureError }
export default methods;

Example use case

import { captureError, debug } from "./logger"

const fooAsync = async () => {
  try {
    // ...
  } catch (error) {
    captureError(error)
  } finally {
    debug(`Completed foo.`)
  }
}

const barSync = (url: string) => {
  fetch(url).then(() => {
    // ...
  }).catch(captureError)
}
@TerryMooreII
Copy link
Collaborator

You should be able to send it to logdna.error() and if the message is an instanceof Error then it will send it to captureError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants