Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute/refetch should be async #51

Closed
jtparrett opened this issue Oct 23, 2019 · 4 comments · Fixed by #52
Closed

execute/refetch should be async #51

jtparrett opened this issue Oct 23, 2019 · 4 comments · Fixed by #52

Comments

@jtparrett
Copy link

I would like the ability to await refetch/execute and receive the response data in return.

const data = await execute()
// ... use data here
@astone123
Copy link

I'd also like the option to do this. I want to be able to catch the error thrown by the Axios call in my form submit handler.

eg.

try {
  const data = await execute()
} catch (error) {
 // handle request error myself
}

@davidwilson3
Copy link

davidwilson3 commented Oct 23, 2019

I was able to achieve this using the transformResponse portion of the execute function:

const [{ error: fileError }, onSubmit] = useAxios(
        { url: "/api/submit", method: "POST" },
        { manual: true },
    );

onSubmit({
   params: { user: user, filename: "example" },
   data: { body: exampleData },
   transformResponse: [
      (response: string) => {               
         fileError 
            ? errorFunction(response) // do error stuff                             
            :  handleResponseFromAPI(reponse); //do response stuff
      },
],

simoneb added a commit that referenced this issue Oct 23, 2019
@simoneb
Copy link
Owner

simoneb commented Oct 23, 2019

Addressed in version 1.6.0

@jtparrett
Copy link
Author

@simoneb thank you for the quick update, you're a hero 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants