Announcement

Collapse
No announcement yet.

axios get with ToTask gives unexpected result

Collapse
X
  • 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 = result.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 => response.data).ToTask();

    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
Working...
X