Skip to content

Showing non-200 error details in UI #1136

Answered by ChathurangaKCD
Purus asked this question in Q&A
Discussion options

You must be logged in to vote

Both useQuery & useMutation have error property in returned result,
Whatever value thrown from query function can be accessed from error.

//fetch
  const queryResult = useQuery(
    ["GetById", val1, val2],
    (_: string, val1: string, val2: string) => {
      return Axios.get(`${url}/api/${val1}/${val2}`)
        .then((res) => res.data)
        .catch((err) => {
          if (err.response) {
            const { data, status } = err.response;
            if (status === 403) {
              throw { error: "ImportantError", status, data };
            }
          }
          throw { error: "SomeError" };
        });
    }
  );
  const { status, data, error, isError } = queryResult;
//mut…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Purus
Comment options

Answer selected by Purus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants