IdoPesok/zsa

Error messages swallowed up

Closed this issue · 2 comments

I'm not sure if this was intended, but if the handler throws a normal Error, it seems like the error message is replaced with {}. It would be nice if normal exceptions would be wrapped and sent back to the UI as expected.

export const createGroupAction = authenticatedAction
  .createServerAction()
  .input(schema)
  .handler(async ({ input: { name, description }, ctx: { user } }) => {
    throw new Error("GG");
  });
Screenshot 2024-05-30 at 1 00 08 AM

notice how the "GG" shows up nowhere in the ZSAError. I'd personally expect GG to show up in the message property or at least data property

Hi, thanks for bringing this up. This should be resolved now on the latest versions:

"zsa": "^0.2.0",
"zsa-react": "^0.1.1",
"zsa-react-query": "^0.1.0"

Resolution:

err.message will have the string you are looking for. An even easier way, is to not do new Error(...), and just throw a string. This will string will be available in both err.data and err.message

Test case here:

expect(err?.message).toEqual(TEST_DATA.errors.string)

Also wrote up new docs on error handling: https://zsa.vercel.app/errors

Please let me know if something is unclear or doesn't work, will fix ASAP + add to our test suite so it doesn't ever happen again.