如何从成功的 React 查询中获取 HTTP 响应代码?

How do I get the HTTP response code from a successful React query?

如何从成功的 React 查询中获取状态代码?

这是我的自定义挂钩:

const validateIban = async (accountId, encodedIban) => {
    await axios
        .post(`${CUSTOMER_PORTAL_API}/policy/accounts/${accountId}/iban/${encodedIban}`)
};

export function useValidateIban(accountId) {
    return useMutation(encodedIban => validateIban(accountId, encodedIban));
}

这就是我使用 mutate 钩子的地方:

const validateIbanQuery = useValidateIban(accountId)


validateIbanQuery.mutate(encodeURIComponent(iban), {
        onSuccess: () => {
          ******HERE I WANT THE STATUS CODE (204, 202 e.g.)******
        },
        onError: (error) => {
          if (error.response.status === 400) {
            ....
          }
          if (error.response.status === 403) {
            ....
          }
        }
      })

onSuccess回调的第一个参数是AxiosResponse:

axios.post("/api/data", { text }).then(response => {
  console.log(response.status)
  return response; // this response will be passed as the first parameter of onSuccess
});
onSuccess: (data) => {
  console.log(data.status);
},

现场演示