Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Error handling #34

Open
melkir opened this issue May 29, 2023 · 0 comments
Open

Error handling #34

melkir opened this issue May 29, 2023 · 0 comments

Comments

@melkir
Copy link

melkir commented May 29, 2023

I got the following zact code.

export const sendCommand = zact(ActionSchema)(async ({ command, led }) => {
  const res = await fetch(`${process.env.NEXT_HOST_URL}/gpio/command`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ command, led }),
    cache: 'no-store',
  })
  return { status: res.status, statusText: res.statusText }
})

This command might fails and when it does, I got something like this

error Error: connect ECONNREFUSED 127.0.0.1:5002

However, currently the message isn't passed to the client, so I tried to do

 if (!res.ok) throw new Error(await res.text())

But it doesn't seems to work as wanted

const { mutate, error } = useZact(sendCommand)
// error is null
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant