@kubb/plugin-axios 5.5.1 → 5.5.3
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/dist/index.cjs +48 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +49 -17
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/templates/axios.ts +24 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-axios",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.3",
|
|
4
4
|
"description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -65,19 +65,19 @@
|
|
|
65
65
|
"registry": "https://registry.npmjs.org/"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@kubb/plugin-ts": "^5.0.
|
|
69
|
-
"@kubb/plugin-zod": "^5.
|
|
68
|
+
"@kubb/plugin-ts": "^5.0.3",
|
|
69
|
+
"@kubb/plugin-zod": "^5.4.2"
|
|
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.
|
|
75
|
+
"kubb": "^5.4.2",
|
|
76
76
|
"typescript": "^6.0.3"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"axios": "^1.20.0",
|
|
80
|
-
"kubb": "^5.
|
|
80
|
+
"kubb": "^5.4.2"
|
|
81
81
|
},
|
|
82
82
|
"peerDependenciesMeta": {
|
|
83
83
|
"axios": {
|
package/templates/axios.ts
CHANGED
|
@@ -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: {
|
|
335
|
-
|
|
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
|