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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 f458a0d4b..8bd1d5631 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen.ts'; import type { HttpMethod } from '../core/types.gen.ts'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 35f02190c..f0000c3c1 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen.js'; import type { HttpMethod } from '../core/types.gen.js'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 aea2484c7..f81a9e786 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../core/serverSentEvents.gen'; import type { HttpMethod } from '../core/types.gen'; @@ -69,6 +69,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -86,7 +87,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -105,22 +105,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } }; 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 45ce4e81b..f8fe1fa9a 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,206 +352,3 @@ 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 28d35aa5b..fcbbfea0b 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 { AxiosInstance, RawAxiosRequestHeaders } from 'axios'; -import axios, { AxiosError } from 'axios'; +import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios'; +import axios from 'axios'; import { createSseClient } from '../../client-core/bundle/serverSentEvents'; import type { HttpMethod } from '../../client-core/bundle/types'; @@ -67,6 +67,7 @@ export const createClient = (config: Config = {}): Client => { return { opts, url }; }; + // @ts-expect-error const request: Client['request'] = async (options) => { // @ts-expect-error const { opts, url } = await beforeRequest(options); @@ -84,7 +85,6 @@ export const createClient = (config: Config = {}): Client => { params: opts.paramsSerializer ? opts.query : undefined, url, }); - if (response instanceof Error) throw response; let { data } = response; @@ -103,22 +103,13 @@ export const createClient = (config: Config = {}): Client => { data: data ?? {}, }; } catch (error) { + const e = error as AxiosError; if (opts.throwOnError) { - throw error; + throw e; } - - if (error instanceof AxiosError) { - // @ts-expect-error - error.error = error.response?.data ?? {}; - return error; - } - - if (typeof error === 'object' && error !== null) { - error.error = {}; - return error; - } - - return { error: {} }; + // @ts-expect-error + e.error = e.response?.data ?? {}; + return e; } };