@kubb/plugin-fetch 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-fetch",
3
- "version": "5.5.0",
3
+ "version": "5.5.2",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on the native Fetch api.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -66,16 +66,16 @@
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
- "kubb": "^5.3.14",
74
+ "kubb": "^5.3.19",
75
75
  "typescript": "^6.0.3"
76
76
  },
77
77
  "peerDependencies": {
78
- "kubb": "^5.3.14"
78
+ "kubb": "^5.3.19"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=22"
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 pluginFetch = definePlugin<PluginFetch>((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(fetchClientTemplatePath, ctx.config),
98
+ copy: fetchClientTemplatePath,
100
99
  footer: baseURLExpression ? `client.setConfig({ baseURL: ${baseURLExpression} })` : undefined,
101
100
  })
102
101
 
@@ -357,8 +357,21 @@ export class ResponseError<TError = unknown, TRequest = Request, TResponse = Res
357
357
  request: TRequest
358
358
  response: TResponse
359
359
 
360
- constructor(config: { data: TError; status: number; statusText: string; contentType?: string; request: TRequest; response: TResponse }) {
361
- super(`Request failed with status ${config.status}${config.statusText ? ` ${config.statusText}` : ''}`)
360
+ constructor(config: {
361
+ data: TError
362
+ status: number
363
+ statusText: string
364
+ contentType?: string
365
+ request: TRequest
366
+ response: TResponse
367
+ method?: string
368
+ url?: string
369
+ }) {
370
+ // The query and hash are left out: sensitive query parameters or fragments must not reach logs.
371
+ const cleanUrl = config.url?.split(/[?#]/)[0]
372
+ const target = [config.method, cleanUrl].filter(Boolean).join(' ')
373
+ const statusText = config.statusText?.trim()
374
+ super(`${target ? `${target} failed` : 'Request failed'} with status ${config.status}${statusText ? ` ${statusText}` : ''}`)
362
375
  this.name = 'ResponseError'
363
376
  this.data = config.data
364
377
  this.status = config.status
@@ -367,6 +380,13 @@ export class ResponseError<TError = unknown, TRequest = Request, TResponse = Res
367
380
  this.request = config.request
368
381
  this.response = config.response
369
382
  }
383
+
384
+ /**
385
+ * Matches on `name`, not `instanceof`: every generated client bundles its own `ResponseError` class.
386
+ */
387
+ static is(error: unknown): error is ResponseError<unknown, unknown, unknown> {
388
+ return error instanceof Error && error.name === 'ResponseError'
389
+ }
370
390
  }
371
391
 
372
392
  export type ResponseErrorConfig<TError = unknown> = ResponseError<TError>
@@ -680,6 +700,8 @@ async function settleResult<TRequest, TResponse>({
680
700
  contentType,
681
701
  request: result.request,
682
702
  response: result.response,
703
+ method: request.method,
704
+ url: request.url,
683
705
  })
684
706
  await errorInterceptors.run(responseError, requestConfig)
685
707
  throw responseError