@@ -12,10 +12,19 @@ export const DEFAULT_SUCCESS_STATUS_CODES = [
1212 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 226 , 300 , 301 , 302 , 303 , 304 , 305 , 306 , 307 , 308 ,
1313] as const ;
1414
15+ // Default error status codes (4xx and 5xx ranges)
16+ export const DEFAULT_ERROR_STATUS_CODES = [
17+ 400 , 401 , 402 , 403 , 404 , 405 , 406 , 407 , 408 , 409 , 410 , 411 , 412 , 413 , 414 , 415 , 416 , 417 , 418 , 421 , 422 , 423 , 424 ,
18+ 425 , 426 , 428 , 429 , 431 , 451 , 500 , 501 , 502 , 503 , 504 , 505 , 506 , 507 , 508 , 510 , 511 ,
19+ ] as const ;
20+
21+ export type ErrorStatusCode = ( typeof DEFAULT_ERROR_STATUS_CODES ) [ number ] ;
22+
1523type GeneratorOptions = ReturnType < typeof mapOpenApiEndpoints > & {
1624 runtime ?: "none" | keyof typeof runtimeValidationGenerator ;
1725 schemasOnly ?: boolean ;
1826 successStatusCodes ?: readonly number [ ] ;
27+ errorStatusCodes ?: readonly number [ ] ;
1928 includeClient ?: boolean ;
2029} ;
2130type GeneratorContext = Required < GeneratorOptions > ;
@@ -71,6 +80,7 @@ export const generateFile = (options: GeneratorOptions) => {
7180 ...options ,
7281 runtime : options . runtime ?? "none" ,
7382 successStatusCodes : options . successStatusCodes ?? DEFAULT_SUCCESS_STATUS_CODES ,
83+ errorStatusCodes : options . errorStatusCodes ?? DEFAULT_ERROR_STATUS_CODES ,
7484 includeClient : options . includeClient ?? true ,
7585 } as GeneratorContext ;
7686
@@ -338,7 +348,7 @@ export type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
338348export type Fetcher = (method: Method, url: string, parameters?: EndpointParameters | undefined) => Promise<Response>;
339349
340350// Status code type for success responses
341- export type StatusCode = ${ statusCodeType } ;
351+ export type SuccessStatusCode = ${ statusCodeType } ;
342352
343353// Error handling types
344354export type TypedApiResponse<TSuccess, TAllResponses extends Record<string | number, unknown> = {}> =
@@ -352,7 +362,7 @@ export type TypedApiResponse<TSuccess, TAllResponses extends Record<string | num
352362 : {
353363 [K in keyof TAllResponses]: K extends string
354364 ? K extends \`\${infer TStatusCode extends number}\`
355- ? TStatusCode extends StatusCode
365+ ? TStatusCode extends SuccessStatusCode
356366 ? Omit<Response, "ok" | "status" | "json"> & {
357367 ok: true;
358368 status: TStatusCode;
@@ -367,7 +377,7 @@ export type TypedApiResponse<TSuccess, TAllResponses extends Record<string | num
367377 }
368378 : never
369379 : K extends number
370- ? K extends StatusCode
380+ ? K extends SuccessStatusCode
371381 ? Omit<Response, "ok" | "status" | "json"> & {
372382 ok: true;
373383 status: K;
0 commit comments