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

fix(useAxios): assign AxiosError to error.value when no url provided (close #2478) #2484

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/integrations/useAxios/index.ts
Original file line number Diff line number Diff line change
@@ -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