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

Unable to use instanceof TRPCClientError #209

Open
Ryanjso opened this issue Dec 4, 2024 · 1 comment
Open

Unable to use instanceof TRPCClientError #209

Ryanjso opened this issue Dec 4, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@Ryanjso
Copy link

Ryanjso commented Dec 4, 2024

I'm having trouble getting errors to show up correctly as instances of the TRPCClientError class.
If you console.log(err.constructor.name) it's always _y

It seems it's being minified by Vite somewhere but I've played with the configuration a lot and can't seem to figure out anything different.

I realize this may be a Vite issue more so than an electron-trpc issue but I imagine everyone here is likely facing this so curious of a fix.

This issue happens in my own repo and this repos example basic-react project

import { TRPCClientError } from '@trpc/react-query'; // same issue even if you import from '@trpc/client'

 try {
          await mutateAsync();
        } catch (err) {
          if (err instanceof TRPCClientError) {
            // never happens :(
          } 
        }
@Ryanjso
Copy link
Author

Ryanjso commented Dec 4, 2024

This is my way of hacking it for now, but obviously less than ideal

export const isTRPCClientError = (error: unknown): error is TRPCClientError<AppRouter> => {
  return typeof error === 'object' && error !== null && error['name'] === 'TRPCClientError'
}

// inside catch block
if (isTRPCClientError(error)) {
        // error is now a TRPCClientError
}

@jsonnull jsonnull added the help wanted Extra attention is needed label Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants