@@ -10,7 +10,7 @@ import { type Fetch, URLSearchParams } from './globals'
1010 */
1111export type ZodFetcher = < Schema extends z . ZodTypeAny > (
1212 schema : Schema ,
13- expectedContentType : ContentType ,
13+ expectedContentType : ContentType | ContentType [ ] ,
1414 ...args : Parameters < Fetch >
1515) => Promise < { response : Awaited < ReturnType < Fetch > > ; result ?: z . SafeParseReturnType < Schema , z . infer < Schema > > } >
1616
@@ -62,15 +62,17 @@ export function createZodFetcher(fetcher?: Fetch): ZodFetcher {
6262 return async ( schema , expectedContentType , ...args ) => {
6363 const response = await createFetcher ( fetcher ) ( ...args )
6464
65- if ( response . ok && ! isResponseContentType ( expectedContentType , response ) ) {
65+ const expectedContentTypeArray = Array . isArray ( expectedContentType ) ? expectedContentType : [ expectedContentType ]
66+
67+ if ( response . ok && ! isResponseContentType ( expectedContentTypeArray , response ) ) {
6668 throw new InvalidFetchResponseError (
67- `Expected response to match content type ' ${ expectedContentType } ' , but received '${ response . headers . get ( 'Content-Type' ) } '` ,
69+ `Expected response to match content type ${ expectedContentTypeArray . join ( ' | ' ) } , but received '${ response . headers . get ( 'Content-Type' ) } '` ,
6870 await response . clone ( ) . text ( ) ,
6971 response
7072 )
7173 }
7274
73- if ( expectedContentType === ContentType . OAuthAuthorizationRequestJwt ) {
75+ if ( expectedContentTypeArray . includes ( ContentType . OAuthAuthorizationRequestJwt ) ) {
7476 return {
7577 response,
7678 result : response . ok ? schema . safeParse ( await response . text ( ) ) : undefined ,
0 commit comments