diff --git a/examples/openapi-ts-axios/src/client/client/client.gen.ts b/examples/openapi-ts-axios/src/client/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/examples/openapi-ts-axios/src/client/client/client.gen.ts +++ b/examples/openapi-ts-axios/src/client/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/content-types/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/parameter-explode-false-axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-false/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-number/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-strict/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/base-url-string/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/clean-false/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/default/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/client.gen.ts index 8bd1d5631c..8a04e28417 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/import-file-extension-ts/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen.ts'; import type { HttpMethod } from '../core/types.gen.ts'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-optional/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/sdk-client-required/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/client.gen.ts index f0000c3c17..e0f3555700 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/tsconfig-nodenext-sdk/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen.js'; import type { HttpMethod } from '../core/types.gen.js'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/content-types/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/parameter-explode-false-axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/angular-query-experimental/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/react-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/solid-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/svelte-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@tanstack/vue-query/axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/client.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/client.gen.ts index f81a9e7863..262b968270 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/client.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/sse-axios/client/client.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,7 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -87,6 +87,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -105,13 +106,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } }; diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-axios/__tests__/client.test.ts b/packages/openapi-ts/src/plugins/@hey-api/client-axios/__tests__/client.test.ts index f8fe1fa9a2..45ce4e81bc 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-axios/__tests__/client.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-axios/__tests__/client.test.ts @@ -352,3 +352,206 @@ describe('confirming axios behaviour for constructing URLs', () => { expect(config).toBe('https://api.example.com/users'); }); }); + +describe('error handling', () => { + it('should handle 404 response when throwOnError is false', async () => { + const client = createClient({ baseURL: 'https://api.example.com' }); + + const errorData = { error: 'Resource not found' }; + const axiosError = new axios.AxiosError( + 'Request failed with status code 404', + 'ERR_BAD_REQUEST', + {} as any, + {}, + { + config: {} as any, + data: errorData, + headers: {}, + status: 404, + statusText: 'Not Found', + }, + ); + + const mockAxios = vi.fn().mockResolvedValue(axiosError); + + const result = await client.get({ + axios: mockAxios as Partial as AxiosInstance, + headers: {}, + throwOnError: false, + url: '/users/999', + }); + + expect(mockAxios).toHaveBeenCalledWith( + expect.objectContaining({ + url: 'https://api.example.com/users/999', + }), + ); + expect(result).toBeInstanceOf(axios.AxiosError); + expect(result).toMatchObject({ + error: errorData, + response: { + data: errorData, + status: 404, + statusText: 'Not Found', + }, + }); + }); + + it('should throw 404 error when throwOnError is true', async () => { + const client = createClient({ baseURL: 'https://api.example.com' }); + + const errorData = { error: 'Resource not found' }; + const axiosError = new axios.AxiosError( + 'Request failed with status code 404', + 'ERR_BAD_REQUEST', + {} as any, + {}, + { + config: {} as any, + data: errorData, + headers: {}, + status: 404, + statusText: 'Not Found', + }, + ); + + const mockAxios = vi.fn().mockResolvedValue(axiosError); + + await expect( + client.get({ + axios: mockAxios as Partial as AxiosInstance, + headers: {}, + throwOnError: true, + url: '/users/999', + }), + ).rejects.toMatchObject({ + response: { + data: errorData, + status: 404, + statusText: 'Not Found', + }, + }); + }); + + it('should handle ECONNREFUSED error when throwOnError is false', async () => { + const client = createClient({ baseURL: 'https://api.example.com' }); + + const connectionError = axios.AxiosError.from( + new AggregateError( + [ + new Error('connect ECONNREFUSED ::1:3000'), + new Error('connect ECONNREFUSED 127.0.0.1:3000'), + ], + 'Error', + ), + 'ECONNREFUSED', + {} as any, + {}, + undefined, // no response object for connection errors + ); + + const mockAxios = vi.fn().mockResolvedValue(connectionError); + + const result = await client.get({ + axios: mockAxios as Partial as AxiosInstance, + headers: {}, + throwOnError: false, + url: '/users', + }); + + expect(mockAxios).toHaveBeenCalledWith( + expect.objectContaining({ + url: 'https://api.example.com/users', + }), + ); + expect(result).toMatchObject({ + code: 'ECONNREFUSED', + error: {}, // error.response?.data ?? {} + message: 'Error', + }); + }); + + it('should throw ECONNREFUSED error when throwOnError is true', async () => { + const client = createClient({ baseURL: 'https://api.example.com' }); + + const connectionError = axios.AxiosError.from( + new AggregateError( + [ + new Error('connect ECONNREFUSED ::1:3000'), + new Error('connect ECONNREFUSED 127.0.0.1:3000'), + ], + 'Error', + ), + 'ECONNREFUSED', + {} as any, + {}, + undefined, + ); + + const mockAxios = vi.fn().mockResolvedValue(connectionError); + + await expect( + client.get({ + axios: mockAxios as Partial as AxiosInstance, + headers: {}, + throwOnError: true, + url: '/users', + }), + ).rejects.toMatchObject({ + code: 'ECONNREFUSED', + message: 'Error', + name: 'AggregateError', + }); + }); + + it('should handle non-object error from responseValidator when throwOnError is false', async () => { + const client = createClient({ baseURL: 'https://api.example.com' }); + + const mockAxios = vi.fn().mockResolvedValue({ + data: { id: 1, name: 'test' }, + headers: {}, + status: 200, + statusText: 'OK', + }); + + const result = await client.get({ + axios: mockAxios as Partial as AxiosInstance, + headers: {}, + responseType: 'json', + responseValidator: vi.fn().mockRejectedValue('validation failed'), + throwOnError: false, + url: '/users/1', + }); + + expect(mockAxios).toHaveBeenCalledWith( + expect.objectContaining({ + url: 'https://api.example.com/users/1', + }), + ); + expect(result).toEqual({ + error: {}, + }); + }); + + it('should throw non-object error from responseValidator when throwOnError is true', async () => { + const client = createClient({ baseURL: 'https://api.example.com' }); + + const mockAxios = vi.fn().mockResolvedValue({ + data: { id: 1, name: 'test' }, + headers: {}, + status: 200, + statusText: 'OK', + }); + + await expect( + client.get({ + axios: mockAxios as Partial as AxiosInstance, + headers: {}, + responseType: 'json', + responseValidator: vi.fn().mockRejectedValue('non-object error'), + throwOnError: true, + url: '/users/1', + }), + ).rejects.toBe('non-object error'); + }); +}); diff --git a/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/client.ts b/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/client.ts index fcbbfea0bf..6b6eaee175 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/client.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/client-axios/bundle/client.ts @@ -1,5 +1,5 @@ -import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios from 'axios'; +import type { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios, { AxiosError } from 'axios'; import { createSseClient } from '../../client-core/bundle/serverSentEvents'; import type { HttpMethod } from '../../client-core/bundle/types'; @@ -67,7 +67,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; - // @ts-expect-error + // @ts-expect-error is not assignable to type RequestResult const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -85,6 +85,7 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); + if (response instanceof Error) throw response; let { data } = response; @@ -103,13 +104,17 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { - const e = error as AxiosError; if (opts.throwOnError) { - throw e; + throw error; } - // @ts-expect-error - e.error = e.response?.data ?? {}; - return e; + + if (error instanceof AxiosError) { + // @ts-expect-error Property 'error' does not exist on type 'AxiosError'.ts(2339) + error.error = error.response?.data ?? {}; + return error; + } + + return { error: {} }; } };