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

captureException is potentially undefined #5

Open
nathanbrachotte opened this issue Jan 9, 2024 · 3 comments
Open

captureException is potentially undefined #5

nathanbrachotte opened this issue Jan 9, 2024 · 3 comments

Comments

@nathanbrachotte
Copy link

Hey there,
trying to implement captureException from useBaselimeRum.
This hooks return type is

{
    setUser: (userId?: string) => void;
    sendEvent: (message: string, data?: any) => void;
    config?: undefined;
    _trackWebVital?: undefined;
    captureException?: undefined; // undefined here
} | {
    config: BaselimeRumConfig;
    setUser: (userId?: string) => void;
    _trackWebVital: (metric: any) => void;
    captureException: (error: Error, info?: React$1.ErrorInfo) => Promise<void>;
    sendEvent: (message: string, data?: any) => void;
}

I'm curious to know in which context captureException would not be defined.

@Meags27
Copy link

Meags27 commented Apr 9, 2024

I have the same issue, typescript throwing warnings that it could be undefined. "TS2722: Cannot invoke an object which is possibly undefined"

 catch (error) {
      setIsSending(false);
      if (error instanceof Error) {
        setErrorMessage(error.message);
        captureException(error);
      }
    }

@Ankcorn
Copy link
Contributor

Ankcorn commented Apr 9, 2024

Hey,

captureException is undefined if you are using it outside of the BaselimeRumContext. It should probably just be a no-op in this scenario rather than undefined so I will fix that.

In the meantime you can call the method like this

captureException?.()

Which should hopefully silence your TS error

@Ankcorn
Copy link
Contributor

Ankcorn commented Apr 14, 2024

Thank you @Meags27 and @nathanbrachotte. This is fixed in 0.2.9

Sorry its so late. I hope this helps

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

3 participants