File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest'
2+ import { createOpenFetch } from '../fetch'
3+ import type { paths } from '#/generated/api-schema'
4+
5+ describe ( 'fetch' , ( ) => {
6+ it ( 'should fill path correctly' , async ( ) => {
7+ const $fetch = createOpenFetch < paths > ( {
8+ baseURL : 'https://api.example.com' ,
9+ } )
10+
11+ await $fetch ( '/auth/login' , {
12+ method : 'POST' ,
13+ body : {
14+ email : 'admin@example.com' ,
15+ password : 'password' ,
16+ } ,
17+ } )
18+
19+ await $fetch ( '/pets/{id}' , { } )
20+ } )
21+ } )
Original file line number Diff line number Diff line change @@ -74,10 +74,11 @@ export type OpenFetchClient<Paths> = <
7474 ? 'get'
7575 : LowercasedMethod ,
7676 ResT = FetchResponseData < Paths [ ReqT ] [ DefaultMethod ] > ,
77+ ErrorT = FetchResponseError < Methods [ DefaultMethod ] > ,
7778> (
7879 url : ReqT ,
7980 options ?: OpenFetchOptions < Method , LowercasedMethod , Methods > ,
80- ) => Promise < ResT >
81+ ) => Promise < ResT | ErrorT >
8182
8283// More flexible way to rewrite the request path,
8384// but has problems - https://github.com/unjs/ofetch/issues/319
@@ -91,7 +92,7 @@ export function openFetchRequestInterceptor(ctx: FetchContext) {
9192export function createOpenFetch < Paths > (
9293 options : FetchOptions | ( ( options : FetchOptions ) => FetchOptions ) ,
9394) : OpenFetchClient < Paths > {
94- return ( url : string , opts : any ) => {
95+ return ( url : string , opts : any = { } ) => {
9596 return $fetch (
9697 fillPath ( url , opts ?. path ) ,
9798 typeof options === 'function'
You can’t perform that action at this time.
0 commit comments