Skip to content

Commit

Permalink
fix(useAxios): assign AxiosError to error.value when no url provided (c…
Browse files Browse the repository at this point in the history
…lose #2478) (#2484)

* fix(useAxios): assign AxiosError to error.value when no url provided

* fix(useAxios): remove default empty string for request url

Co-authored-by: wheat <jacobrclevenger@gmail.com>
  • Loading branch information
Yiyang Sun and wheatjs committed Jan 9, 2023
1 parent 6cbf4a0 commit 1e27060
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/integrations/useAxios/index.ts
@@ -1,8 +1,8 @@
import type { Ref, ShallowRef } from 'vue-demi'
import { ref, shallowRef } from 'vue-demi'
import { isString, until } from '@vueuse/shared'
import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, CancelTokenSource } from 'axios'
import axios from 'axios'
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, CancelTokenSource } from 'axios'
import axios, { AxiosError } from 'axios'

export interface UseAxiosReturn<T, R = AxiosResponse<T>, D = any> {
/**
Expand Down Expand Up @@ -178,7 +178,14 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
error.value = undefined
const _url = typeof executeUrl === 'string'
? executeUrl
: url ?? ''
: url ?? config.url

if (_url === undefined) {
error.value = new AxiosError(AxiosError.ERR_INVALID_URL)
isFinished.value = true
return { then }
}

loading(true)
instance(_url, { ...defaultConfig, ...typeof executeUrl === 'object' ? executeUrl : config, cancelToken: cancelToken.token })
.then((r: any) => {
Expand Down

0 comments on commit 1e27060

Please sign in to comment.