@kubb/plugin-axios 5.5.0 → 5.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-axios",
3
- "version": "5.5.0",
3
+ "version": "5.5.2",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -66,18 +66,18 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "@kubb/plugin-ts": "^5.0.2",
69
- "@kubb/plugin-zod": "^5.2.1"
69
+ "@kubb/plugin-zod": "^5.4.0"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@internals/client": "0.0.0",
73
73
  "@internals/shared": "0.0.0",
74
74
  "axios": "^1.20.0",
75
- "kubb": "^5.3.14",
75
+ "kubb": "^5.3.19",
76
76
  "typescript": "^6.0.3"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "axios": "^1.20.0",
80
- "kubb": "^5.3.14"
80
+ "kubb": "^5.3.19"
81
81
  },
82
82
  "peerDependenciesMeta": {
83
83
  "axios": {
package/src/plugin.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from 'node:path'
2
- import { createSdkGenerator, defaultMacros, resolverClient, runtimeTemplate } from '@internals/client'
2
+ import { createSdkGenerator, defaultMacros, resolverClient } from '@internals/client'
3
3
  import { createGroupConfig } from '@internals/shared'
4
4
  import { definePlugin, Resolver } from 'kubb/kit'
5
5
  import { pluginTsName } from '@kubb/plugin-ts'
@@ -95,8 +95,7 @@ export const pluginAxios = definePlugin<PluginAxios>((options) => {
95
95
  ctx.injectFile({
96
96
  baseName: 'client.ts',
97
97
  path: path.resolve(root, '.kubb/client.ts'),
98
- // Keep sources empty so the barrel exports the whole runtime module.
99
- banner: runtimeTemplate(axiosClientTemplatePath, ctx.config),
98
+ copy: axiosClientTemplatePath,
100
99
  footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : undefined,
101
100
  })
102
101
 
@@ -331,8 +331,21 @@ export class ResponseError<TError = unknown, TRequest = AxiosRequestConfig, TRes
331
331
  request: TRequest
332
332
  response: TResponse
333
333
 
334
- constructor(config: { data: TError; status: number; statusText: string; contentType?: string; request: TRequest; response: TResponse }) {
335
- super(`Request failed with status ${config.status}${config.statusText ? ` ${config.statusText}` : ''}`)
334
+ constructor(config: {
335
+ data: TError
336
+ status: number
337
+ statusText: string
338
+ contentType?: string
339
+ request: TRequest
340
+ response: TResponse
341
+ method?: string
342
+ url?: string
343
+ }) {
344
+ // The query and hash are left out: sensitive query parameters or fragments must not reach logs.
345
+ const cleanUrl = config.url?.split(/[?#]/)[0]
346
+ const target = [config.method, cleanUrl].filter(Boolean).join(' ')
347
+ const statusText = config.statusText?.trim()
348
+ super(`${target ? `${target} failed` : 'Request failed'} with status ${config.status}${statusText ? ` ${statusText}` : ''}`)
336
349
  this.name = 'ResponseError'
337
350
  this.data = config.data
338
351
  this.status = config.status
@@ -341,6 +354,13 @@ export class ResponseError<TError = unknown, TRequest = AxiosRequestConfig, TRes
341
354
  this.request = config.request
342
355
  this.response = config.response
343
356
  }
357
+
358
+ /**
359
+ * Matches on `name`, not `instanceof`: every generated client bundles its own `ResponseError` class.
360
+ */
361
+ static is(error: unknown): error is ResponseError<unknown, unknown, unknown> {
362
+ return error instanceof Error && error.name === 'ResponseError'
363
+ }
344
364
  }
345
365
 
346
366
  export type ResponseErrorConfig<TError = unknown> = ResponseError<TError>
@@ -753,6 +773,8 @@ export function createClientCore<TRequest = AxiosRequestConfig, TResponse = Axio
753
773
  contentType: getResponseContentType(axiosError.response.headers as Record<string, unknown>),
754
774
  request: axiosError.config as TRequest,
755
775
  response: axiosError.response as TResponse,
776
+ method: axiosError.config?.method?.toUpperCase(),
777
+ url: [axiosError.config?.baseURL?.replace(/\/+$/, ''), axiosError.config?.url].filter(Boolean).join(''),
756
778
  })
757
779
  }
758
780
  throw error