No announcement yet.

axios get with ToTask gives unexpected result

  • Filter
  • Time
  • Show
Clear All
new posts

    axios get with ToTask gives unexpected result

    It looks like there is a bug either in axios retyped library or in the ToTask in general. Here is the line of code

    axios.AxiosResponse<T> result = await axios.Axios.get<T>($"{API_URL}{String.Format(url, parameter)}").ToTask();

    If the url argument is right it's supposed to return AxiosResponse<T> object. In reality the javascript object which is returned is an array where the only item in it is that AxiosResponse<T>. So if I try to do var data =; the data is undefined because it tries to get a value of the data property but against an array object. A workaround that I found is this

    T result = await axios.Axios.get<T>($"{API_URL}{String.Format(url, parameter)}").then(response =>;

    Somehow if the response object goes to "then" method it is correct there. It is actually of AxiosResponse<T> type. Do you think there is a bug somewhere in this regards? Is there a better workaround for now without using "then" method?

    Thank you

    Hello @alex4998!

    This looks like an async-await issue. Or at least has good chances to be one. We've fixed some issues related to that since you sent your inquire, I wonder if that's fixed at this point?

    I believe we won't have this library in deck to ask you for a test case there, but if you happen to be able to provide complete instructions. Maybe a simple project you shared in github -- that has only the essential code to reproduce the issue could help us reproduce the issue on our side.

    Besides, it would really help everyone if you wrapped code blocks within [ var][ /var] (inline) or [code][/code] blocks (multiline) for better readability of the code lines you wanted to share.