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

Error handling #34

@melkir

Description

@melkir

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions