[{"data":1,"prerenderedAt":1603,"buildId":1604},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Ferror-handling":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":1602,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Ferror-handling.md",{},"Handle errors",{"type":8,"value":9,"toc":1581},"minimark",[10,23,28,35,136,158,162,176,360,478,494,517,521,544,706,714,718,733,849,856,860,876,978,982,996,1101,1121,1148,1185,1198,1303,1336,1343,1347,1356,1422,1446,1450,1454,1464,1467,1475,1509,1516,1534,1540,1564],[11,12,13,14,18,19,22],"p",{},"Handle HTTP and network errors in the generated Fetch client with ",[15,16,17],"code",{},"ResponseError",", or return errors as values with ",[15,20,21],{},"throwOnError: false",".",[24,25,27],"h2",{"id":26},"what-a-call-does","What a call does",[11,29,30,31,34],{},"Only a non-2xx response depends on ",[15,32,33],{},"throwOnError",":",[36,37,38,51],"table",{},[39,40,41],"thead",{},[42,43,44,48],"tr",{},[45,46,47],"th",{},"What happens",[45,49,50],{},"Result",[52,53,54,66,87,101,110,125],"tbody",{},[42,55,56,60],{},[57,58,59],"td",{},"2xx response",[57,61,62,63,22],{},"Resolves with ",[15,64,65],{},"data",[42,67,68,71],{},[57,69,70],{},"Non-2xx response",[57,72,73,74,76,77,79,80,83,84,22],{},"Throws a ",[15,75,17],{},". With ",[15,78,21],{},", resolves with ",[15,81,82],{},"error"," and ",[15,85,86],{},"status",[42,88,89,96],{},[57,90,91,92,95],{},"A body fails its schema (",[15,93,94],{},"validator"," on)",[57,97,73,98,22],{},[15,99,100],{},"ValidationError",[42,102,103,106],{},[57,104,105],{},"Invalid JSON under a JSON media type",[57,107,73,108,22],{},[15,109,100],{},[42,111,112,115],{},[57,113,114],{},"Network or DNS failure",[57,116,117,118,121,122,22],{},"Rejects with the ",[15,119,120],{},"TypeError"," from ",[15,123,124],{},"fetch",[42,126,127,133],{},[57,128,129,130],{},"Aborted ",[15,131,132],{},"signal",[57,134,135],{},"Rejects with the signal's reason.",[11,137,138,139,142,143,150,151,153,154,157],{},"Every failure that rejects with an ",[15,140,141],{},"Error"," also reaches ",[144,145,147],"a",{"href":146},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fconfigure-requests#add-interceptors",[15,148,149],{},"client.interceptors.error",". An abort whose reason is not an ",[15,152,141],{},", such as ",[15,155,156],{},"abort('canceled')",", skips it.",[24,159,161],{"id":160},"catch-a-responseerror","Catch a ResponseError",[11,163,164,165,168,169,172,173,175],{},"Narrow with ",[15,166,167],{},"ResponseError.is(error)"," instead of ",[15,170,171],{},"instanceof",", because each generated package bundles its own ",[15,174,17],{}," class:",[177,178,182],"pre",{"language":179,"code":180,"class":181},"typescript","import { getPetById } from '.\u002Fgen\u002Fclients\u002FgetPetById'\nimport { ResponseError } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\ntry {\n const { data } = await getPetById({ path: { petId: 1 } })\n} catch (error) {\n if (ResponseError.is(error)) console.error(error.status, error.data) \u002F\u002F 404, the parsed error body\n}","highlights",[15,183,185,212,213,212,230,212,232,212,240,212,286,212,301,212,355],{"class":184},"language-typescript",[186,187,190,194,198,202,205,208],"span",{"class":188,"style":189},"line","display: inline",[186,191,193],{"style":192},"color:#d73a49;--hls-dark:#f97583","import ",[186,195,197],{"style":196},"color:#005cc5;--hls-dark:#79b8ff","{ ",[186,199,201],{"style":200},"color:#24292e;--hls-dark:#e1e4e8","getPetById ",[186,203,204],{"style":196},"} ",[186,206,207],{"style":192},"from ",[186,209,211],{"style":210},"color:#032f62;--hls-dark:#9ecbff","'.\u002Fgen\u002Fclients\u002FgetPetById'","\n",[186,214,215,217,219,223,225,227],{"class":188,"style":189},[186,216,193],{"style":192},[186,218,197],{"style":196},[186,220,222],{"style":221},"color:#6f42c1;--hls-dark:#b392f0","ResponseError ",[186,224,204],{"style":196},[186,226,207],{"style":192},[186,228,229],{"style":210},"'.\u002Fgen\u002F.kubb\u002Fclient'",[186,231],{"class":188,"style":189},[186,233,234,237],{"class":188,"style":189},[186,235,236],{"style":192},"try ",[186,238,239],{"style":196},"{",[186,241,242,245,248,250,253,255,258,261,264,267,270,273,275,278,280,283],{"class":188,"style":189},[186,243,244],{"style":196}," ",[186,246,247],{"style":192},"const ",[186,249,197],{"style":196},[186,251,252],{"style":200},"data ",[186,254,204],{"style":196},[186,256,257],{"style":192},"= ",[186,259,260],{"style":192},"await ",[186,262,263],{"style":221},"getPetById",[186,265,266],{"style":196},"({ ",[186,268,269],{"style":196},"path",[186,271,272],{"style":192},": ",[186,274,197],{"style":196},[186,276,277],{"style":196},"petId",[186,279,272],{"style":192},[186,281,282],{"style":196},"1 ",[186,284,285],{"style":196},"} })",[186,287,288,290,293,296,298],{"class":188,"style":189},[186,289,204],{"style":196},[186,291,292],{"style":192},"catch ",[186,294,295],{"style":196},"(",[186,297,82],{"style":200},[186,299,300],{"style":196},") {",[186,302,303,305,308,310,312,314,317,319,321,324,327,329,331,333,335,337,339,342,344,346,348,351],{"class":188,"style":189},[186,304,244],{"style":196},[186,306,307],{"style":192},"if ",[186,309,295],{"style":196},[186,311,17],{"style":221},[186,313,22],{"style":192},[186,315,316],{"style":221},"is",[186,318,295],{"style":196},[186,320,82],{"style":200},[186,322,323],{"style":196},")) ",[186,325,326],{"style":200},"console",[186,328,22],{"style":192},[186,330,82],{"style":221},[186,332,295],{"style":196},[186,334,82],{"style":200},[186,336,22],{"style":192},[186,338,86],{"style":196},[186,340,341],{"style":192},", ",[186,343,82],{"style":200},[186,345,22],{"style":192},[186,347,65],{"style":196},[186,349,350],{"style":196},") ",[186,352,354],{"style":353},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F 404, the parsed error body",[186,356,357],{"class":188,"style":189},[186,358,359],{"style":196},"}",[177,361,363],{"language":179,"code":362,"class":181},"class ResponseError extends Error {\n data: TError \u002F\u002F the parsed error body\n status: number\n statusText: string\n contentType: string | undefined\n headers: Headers \u002F\u002F such as error.headers.get('Retry-After')\n request: Request\n response: Response\n}",[15,364,365,212,380,212,394,212,405,212,417,212,435,212,450,212,462,212,474],{"class":184},[186,366,367,370,372,375,378],{"class":188,"style":189},[186,368,369],{"style":192},"class ",[186,371,222],{"style":221},[186,373,374],{"style":192},"extends ",[186,376,377],{"style":221},"Error ",[186,379,239],{"style":196},[186,381,382,384,386,388,391],{"class":188,"style":189},[186,383,244],{"style":196},[186,385,65],{"style":196},[186,387,272],{"style":200},[186,389,390],{"style":221},"TError ",[186,392,393],{"style":353},"\u002F\u002F the parsed error body",[186,395,396,398,400,402],{"class":188,"style":189},[186,397,244],{"style":353},[186,399,86],{"style":200},[186,401,272],{"style":200},[186,403,404],{"style":221},"number",[186,406,407,409,412,414],{"class":188,"style":189},[186,408,244],{"style":221},[186,410,411],{"style":200},"statusText",[186,413,272],{"style":200},[186,415,416],{"style":221},"string",[186,418,419,421,424,426,429,432],{"class":188,"style":189},[186,420,244],{"style":221},[186,422,423],{"style":200},"contentType",[186,425,272],{"style":200},[186,427,428],{"style":221},"string ",[186,430,431],{"style":192},"| ",[186,433,434],{"style":196},"undefined",[186,436,437,439,442,444,447],{"class":188,"style":189},[186,438,244],{"style":196},[186,440,441],{"style":200},"headers",[186,443,272],{"style":200},[186,445,446],{"style":221},"Headers ",[186,448,449],{"style":353},"\u002F\u002F such as error.headers.get('Retry-After')",[186,451,452,454,457,459],{"class":188,"style":189},[186,453,244],{"style":353},[186,455,456],{"style":200},"request",[186,458,272],{"style":200},[186,460,461],{"style":221},"Request",[186,463,464,466,469,471],{"class":188,"style":189},[186,465,244],{"style":221},[186,467,468],{"style":200},"response",[186,470,272],{"style":200},[186,472,473],{"style":221},"Response",[186,475,476],{"class":188,"style":189},[186,477,359],{"style":196},[11,479,480,481,484,485,488,489,83,491,493],{},"The ",[15,482,483],{},"message"," leaves out the query string: ",[15,486,487],{},"GET https:\u002F\u002Fapi.example.com\u002Fpets\u002F1 failed with status 404 Not Found",". ",[15,490,456],{},[15,492,468],{}," keep the full URL, so redact them before you log the whole error.",[495,496,498,499,505,506,509,510,513,514,22],"blockquote",{"as":497},"note","The examples set ",[144,500,502],{"href":501},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fadapter-oas\u002Foptions#integertype",[15,503,504],{},"integerType: 'number'",". With the default ",[15,507,508],{},"bigint",", an ",[15,511,512],{},"int64"," id takes ",[15,515,516],{},"1n",[24,518,520],{"id":519},"narrow-a-thrown-error-by-status","Narrow a thrown error by status",[11,522,523,526,527,529,530,532,533,535,536,539,540,34],{},[15,524,525],{},"isResponseError\u003CResponses>(error)"," narrows a caught error to one operation's ",[15,528,17],{},". A check on ",[15,531,86],{}," then narrows ",[15,534,65],{},". For range keys such as ",[15,537,538],{},"4xx",", see ",[144,541,543],{"href":542},"#status-ranges","Status ranges",[177,545,547],{"language":179,"code":546,"class":181},"import { isResponseError } from '.\u002Fgen\u002F.kubb\u002Fclient'\nimport type { GetPetByIdResponses } from '.\u002Fgen\u002Ftypes\u002FGetPetById'\n\ntry {\n await getPetById({ path: { petId: 7 } })\n} catch (error) {\n if (isResponseError\u003CGetPetByIdResponses>(error) && error.status === 404) {\n console.error(error.data) \u002F\u002F GetPetById404\n }\n}",[15,548,549,212,564,212,583,212,585,212,591,212,616,212,628,212,672,212,696,212,702],{"class":184},[186,550,551,553,555,558,560,562],{"class":188,"style":189},[186,552,193],{"style":192},[186,554,197],{"style":196},[186,556,557],{"style":200},"isResponseError ",[186,559,204],{"style":196},[186,561,207],{"style":192},[186,563,229],{"style":210},[186,565,566,568,571,573,576,578,580],{"class":188,"style":189},[186,567,193],{"style":192},[186,569,570],{"style":200},"type ",[186,572,197],{"style":196},[186,574,575],{"style":221},"GetPetByIdResponses ",[186,577,204],{"style":196},[186,579,207],{"style":192},[186,581,582],{"style":210},"'.\u002Fgen\u002Ftypes\u002FGetPetById'",[186,584],{"class":188,"style":189},[186,586,587,589],{"class":188,"style":189},[186,588,236],{"style":192},[186,590,239],{"style":196},[186,592,593,595,597,599,601,603,605,607,609,611,614],{"class":188,"style":189},[186,594,244],{"style":196},[186,596,260],{"style":192},[186,598,263],{"style":221},[186,600,266],{"style":196},[186,602,269],{"style":196},[186,604,272],{"style":192},[186,606,197],{"style":196},[186,608,277],{"style":196},[186,610,272],{"style":192},[186,612,613],{"style":196},"7 ",[186,615,285],{"style":196},[186,617,618,620,622,624,626],{"class":188,"style":189},[186,619,204],{"style":196},[186,621,292],{"style":192},[186,623,295],{"style":196},[186,625,82],{"style":200},[186,627,300],{"style":196},[186,629,630,632,634,636,639,642,645,648,650,652,654,657,659,661,664,667,670],{"class":188,"style":189},[186,631,244],{"style":196},[186,633,307],{"style":192},[186,635,295],{"style":196},[186,637,638],{"style":200},"isResponseError",[186,640,641],{"style":192},"\u003C",[186,643,644],{"style":221},"GetPetByIdResponses",[186,646,647],{"style":192},">",[186,649,295],{"style":196},[186,651,82],{"style":200},[186,653,350],{"style":196},[186,655,656],{"style":192},"&& ",[186,658,82],{"style":200},[186,660,22],{"style":192},[186,662,663],{"style":196},"status ",[186,665,666],{"style":192},"=== ",[186,668,669],{"style":196},"404",[186,671,300],{"style":196},[186,673,674,677,679,681,683,685,687,689,691,693],{"class":188,"style":189},[186,675,676],{"style":196}," ",[186,678,326],{"style":200},[186,680,22],{"style":192},[186,682,82],{"style":221},[186,684,295],{"style":196},[186,686,82],{"style":200},[186,688,22],{"style":192},[186,690,65],{"style":196},[186,692,350],{"style":196},[186,694,695],{"style":353},"\u002F\u002F GetPetById404",[186,697,698,700],{"class":188,"style":189},[186,699,244],{"style":353},[186,701,359],{"style":196},[186,703,704],{"class":188,"style":189},[186,705,359],{"style":196},[495,707,709,710,713],{"as":708},"warning","The type argument is not checked at runtime, so keep the ",[15,711,712],{},"try"," around one operation.",[24,715,717],{"id":716},"return-the-error-instead","Return the error instead",[11,719,720,721,723,724,726,727,729,730,732],{},"With ",[15,722,21],{},", the call resolves for every status. ",[15,725,65],{}," is set on success and ",[15,728,82],{}," on failure, and a check on ",[15,731,86],{}," narrows both:",[177,734,736],{"language":179,"code":735,"class":181},"const result = await getPetById({ path: { petId: 1 }, throwOnError: false })\n\nif (result.error !== undefined) console.error(result.status, result.error)\nelse console.info(result.data)",[15,737,738,212,779,212,781,212,827],{"class":184},[186,739,740,742,745,747,749,751,753,755,757,759,761,763,765,767,769,771,773,776],{"class":188,"style":189},[186,741,247],{"style":192},[186,743,744],{"style":200},"result ",[186,746,257],{"style":192},[186,748,260],{"style":192},[186,750,263],{"style":221},[186,752,266],{"style":196},[186,754,269],{"style":196},[186,756,272],{"style":192},[186,758,197],{"style":196},[186,760,277],{"style":196},[186,762,272],{"style":192},[186,764,282],{"style":196},[186,766,359],{"style":196},[186,768,341],{"style":192},[186,770,33],{"style":196},[186,772,272],{"style":192},[186,774,775],{"style":196},"false ",[186,777,778],{"style":196},"})",[186,780],{"class":188,"style":189},[186,782,783,785,787,790,792,795,798,800,802,804,806,808,810,812,814,816,818,820,822,824],{"class":188,"style":189},[186,784,307],{"style":192},[186,786,295],{"style":196},[186,788,789],{"style":200},"result",[186,791,22],{"style":192},[186,793,794],{"style":196},"error ",[186,796,797],{"style":192},"!== ",[186,799,434],{"style":196},[186,801,350],{"style":196},[186,803,326],{"style":200},[186,805,22],{"style":192},[186,807,82],{"style":221},[186,809,295],{"style":196},[186,811,789],{"style":200},[186,813,22],{"style":192},[186,815,86],{"style":196},[186,817,341],{"style":192},[186,819,789],{"style":200},[186,821,22],{"style":192},[186,823,82],{"style":196},[186,825,826],{"style":196},")",[186,828,829,832,834,836,839,841,843,845,847],{"class":188,"style":189},[186,830,831],{"style":192},"else ",[186,833,326],{"style":200},[186,835,22],{"style":192},[186,837,838],{"style":221},"info",[186,840,295],{"style":196},[186,842,789],{"style":200},[186,844,22],{"style":192},[186,846,65],{"style":196},[186,848,826],{"style":196},[11,850,851,852,22],{},"See ",[144,853,855],{"href":854},"#empty-error-bodies-and-default-responses","Empty error bodies and default responses",[24,857,859],{"id":858},"set-the-generated-default","Set the generated default",[11,861,862,868,869,871,872,875],{},[144,863,865],{"href":864},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Foptions#throwonerrordefault",[15,866,867],{},"throwOnErrorDefault"," on the plugin sets what a call does when it leaves ",[15,870,33],{}," out. ",[15,873,874],{},"client.setConfig({ throwOnError })"," does not change it:",[177,877,879],{"language":179,"code":878,"class":181},"pluginFetch({ throwOnErrorDefault: false })\n\nconst list = await searchPets({ query: { status: 'available' } }) \u002F\u002F resolves with an error result\nconst pet = await getPetById({ path: { petId: 1 }, throwOnError: true }) \u002F\u002F throws",[15,880,881,212,896,212,898,212,934],{"class":184},[186,882,883,886,888,890,892,894],{"class":188,"style":189},[186,884,885],{"style":221},"pluginFetch",[186,887,266],{"style":196},[186,889,867],{"style":196},[186,891,272],{"style":192},[186,893,775],{"style":196},[186,895,778],{"style":196},[186,897],{"class":188,"style":189},[186,899,900,902,905,907,909,912,914,917,919,921,923,925,928,931],{"class":188,"style":189},[186,901,247],{"style":192},[186,903,904],{"style":200},"list ",[186,906,257],{"style":192},[186,908,260],{"style":192},[186,910,911],{"style":221},"searchPets",[186,913,266],{"style":196},[186,915,916],{"style":196},"query",[186,918,272],{"style":192},[186,920,197],{"style":196},[186,922,86],{"style":196},[186,924,272],{"style":192},[186,926,927],{"style":210},"'available' ",[186,929,930],{"style":196},"} }) ",[186,932,933],{"style":353},"\u002F\u002F resolves with an error result",[186,935,936,938,941,943,945,947,949,951,953,955,957,959,961,963,965,967,969,972,975],{"class":188,"style":189},[186,937,247],{"style":192},[186,939,940],{"style":200},"pet ",[186,942,257],{"style":192},[186,944,260],{"style":192},[186,946,263],{"style":221},[186,948,266],{"style":196},[186,950,269],{"style":196},[186,952,272],{"style":192},[186,954,197],{"style":196},[186,956,277],{"style":196},[186,958,272],{"style":192},[186,960,282],{"style":196},[186,962,359],{"style":196},[186,964,341],{"style":192},[186,966,33],{"style":196},[186,968,272],{"style":192},[186,970,971],{"style":196},"true ",[186,973,974],{"style":196},"}) ",[186,976,977],{"style":353},"\u002F\u002F throws",[24,979,981],{"id":980},"validation-failures","Validation failures",[11,983,720,984,989,990,992,993,34],{},[144,985,987],{"href":986},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Foptions#validator",[15,988,94],{}," on, a body that does not match its Zod schema throws a ",[15,991,100],{}," with the schema's ",[15,994,995],{},"issues",[177,997,999],{"language":179,"code":998,"class":181},"import { ValidationError } from '.\u002Fgen\u002F.kubb\u002FstandardSchema'\n\ntry {\n await getPetById({ path: { petId: 1 } })\n} catch (error) {\n if (error instanceof ValidationError) console.error(error.issues) \u002F\u002F [{ message, path }]\n}",[15,1000,1001,212,1017,212,1019,212,1025,212,1049,212,1061,212,1097],{"class":184},[186,1002,1003,1005,1007,1010,1012,1014],{"class":188,"style":189},[186,1004,193],{"style":192},[186,1006,197],{"style":196},[186,1008,1009],{"style":221},"ValidationError ",[186,1011,204],{"style":196},[186,1013,207],{"style":192},[186,1015,1016],{"style":210},"'.\u002Fgen\u002F.kubb\u002FstandardSchema'",[186,1018],{"class":188,"style":189},[186,1020,1021,1023],{"class":188,"style":189},[186,1022,236],{"style":192},[186,1024,239],{"style":196},[186,1026,1027,1029,1031,1033,1035,1037,1039,1041,1043,1045,1047],{"class":188,"style":189},[186,1028,244],{"style":196},[186,1030,260],{"style":192},[186,1032,263],{"style":221},[186,1034,266],{"style":196},[186,1036,269],{"style":196},[186,1038,272],{"style":192},[186,1040,197],{"style":196},[186,1042,277],{"style":196},[186,1044,272],{"style":192},[186,1046,282],{"style":196},[186,1048,285],{"style":196},[186,1050,1051,1053,1055,1057,1059],{"class":188,"style":189},[186,1052,204],{"style":196},[186,1054,292],{"style":192},[186,1056,295],{"style":196},[186,1058,82],{"style":200},[186,1060,300],{"style":196},[186,1062,1063,1065,1067,1069,1071,1074,1076,1078,1080,1082,1084,1086,1088,1090,1092,1094],{"class":188,"style":189},[186,1064,244],{"style":196},[186,1066,307],{"style":192},[186,1068,295],{"style":196},[186,1070,794],{"style":200},[186,1072,1073],{"style":192},"instanceof ",[186,1075,100],{"style":221},[186,1077,350],{"style":196},[186,1079,326],{"style":200},[186,1081,22],{"style":192},[186,1083,82],{"style":221},[186,1085,295],{"style":196},[186,1087,82],{"style":200},[186,1089,22],{"style":192},[186,1091,995],{"style":196},[186,1093,350],{"style":196},[186,1095,1096],{"style":353},"\u002F\u002F [{ message, path }]",[186,1098,1099],{"class":188,"style":189},[186,1100,359],{"style":196},[11,1102,1103,1105,1106,1109,1110,1113,1114,1117,1118,22],{},[15,1104,100],{}," was called ",[15,1107,1108],{},"ParseError",". The old name is still exported and deprecated, so ",[15,1111,1112],{},"instanceof ParseError"," keeps working. ",[15,1115,1116],{},"error.name"," is now ",[15,1119,1120],{},"'ValidationError'",[11,1122,1123,1124,1126,1127,341,1129,341,1132,1135,1136,1139,1140,1143,1144,1147],{},"A ",[15,1125,100],{}," from a response body also carries ",[15,1128,86],{},[15,1130,1131],{},"method",[15,1133,1134],{},"direction"," (",[15,1137,1138],{},"'response'"," or ",[15,1141,1142],{},"'error'","), and ",[15,1145,1146],{},"source",". So when a non-2xx body does not match its error schema, the status is still there:",[177,1149,1151],{"language":179,"code":1150,"class":181},"if (error instanceof ValidationError && error.status === 404) return null",[15,1152,1153],{"class":184},[186,1154,1155,1157,1159,1161,1163,1165,1167,1169,1171,1173,1175,1177,1179,1182],{"class":188,"style":189},[186,1156,307],{"style":192},[186,1158,295],{"style":196},[186,1160,794],{"style":200},[186,1162,1073],{"style":192},[186,1164,1009],{"style":221},[186,1166,656],{"style":192},[186,1168,82],{"style":200},[186,1170,22],{"style":192},[186,1172,663],{"style":196},[186,1174,666],{"style":192},[186,1176,669],{"style":196},[186,1178,350],{"style":196},[186,1180,1181],{"style":192},"return ",[186,1183,1184],{"style":196},"null",[11,1186,1187,1188,1191,1192,1195,1196,34],{},"To recover from a schema failure, pass ",[15,1189,1190],{},"onValidationError"," on the call or the client. Return ",[15,1193,1194],{},"{ value }"," to use that value, or nothing to throw the ",[15,1197,100],{},[177,1199,1201],{"language":179,"code":1200,"class":181},"client.setConfig({\n onValidationError: (error, { direction, source, value }) => {\n console.warn(direction, source, error.issues)\n return { value }\n },\n})",[15,1202,1203,212,1216,212,1250,212,1279,212,1291,212,1299],{"class":184},[186,1204,1205,1208,1210,1213],{"class":188,"style":189},[186,1206,1207],{"style":200},"client",[186,1209,22],{"style":192},[186,1211,1212],{"style":221},"setConfig",[186,1214,1215],{"style":196},"({",[186,1217,1218,1220,1222,1224,1226,1228,1230,1232,1234,1236,1238,1240,1243,1245,1248],{"class":188,"style":189},[186,1219,244],{"style":196},[186,1221,1190],{"style":196},[186,1223,272],{"style":192},[186,1225,295],{"style":196},[186,1227,82],{"style":200},[186,1229,341],{"style":192},[186,1231,197],{"style":196},[186,1233,1134],{"style":200},[186,1235,341],{"style":192},[186,1237,1146],{"style":200},[186,1239,341],{"style":192},[186,1241,1242],{"style":200},"value ",[186,1244,974],{"style":196},[186,1246,1247],{"style":192},"=> ",[186,1249,239],{"style":196},[186,1251,1252,1254,1256,1258,1261,1263,1265,1267,1269,1271,1273,1275,1277],{"class":188,"style":189},[186,1253,676],{"style":196},[186,1255,326],{"style":200},[186,1257,22],{"style":192},[186,1259,1260],{"style":221},"warn",[186,1262,295],{"style":196},[186,1264,1134],{"style":200},[186,1266,341],{"style":192},[186,1268,1146],{"style":200},[186,1270,341],{"style":192},[186,1272,82],{"style":200},[186,1274,22],{"style":192},[186,1276,995],{"style":196},[186,1278,826],{"style":196},[186,1280,1281,1283,1285,1287,1289],{"class":188,"style":189},[186,1282,676],{"style":196},[186,1284,1181],{"style":192},[186,1286,197],{"style":196},[186,1288,1242],{"style":200},[186,1290,359],{"style":196},[186,1292,1293,1296],{"class":188,"style":189},[186,1294,1295],{"style":196}," }",[186,1297,1298],{"style":192},",",[186,1300,1301],{"class":188,"style":189},[186,1302,778],{"style":196},[11,1304,1305,1306,1308,1309,1311,1312,76,1314,1316,1317,1319,1320,341,1322,1324,1325,1328,1329,1332,1333,22],{},"Invalid JSON does not reach the handler. When the handler returns ",[15,1307,1194],{}," for an error body, the call throws the ",[15,1310,17],{}," as usual, with that value as ",[15,1313,65],{},[15,1315,21],{},", the call resolves with that value as ",[15,1318,82],{}," instead. A ",[15,1321,1184],{},[15,1323,434],{},", or ",[15,1326,1327],{},"''"," value resolves as ",[15,1330,1331],{},"{ status, statusText }",", like an ",[144,1334,1335],{"href":854},"empty error body",[11,1337,1338,1339,22],{},"For which schema checks an error body, see ",[144,1340,1342],{"href":1341},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fserialization#error-body-validation","Error body validation",[24,1344,1346],{"id":1345},"turn-validation-off-at-runtime","Turn validation off at runtime",[11,1348,1349,1351,1352,1355],{},[15,1350,94],{}," decides at generation time which schemas a call carries. ",[15,1353,1354],{},"validate"," skips them at runtime, for example in production or in tests with partial fixtures:",[177,1357,1359],{"language":179,"code":1358,"class":181},"client.setConfig({ validate: import.meta.env.DEV })\nclient.setConfig({ validate: { response: false } }) \u002F\u002F skip one direction",[15,1360,1361,212,1395],{"class":184},[186,1362,1363,1365,1367,1369,1371,1373,1375,1378,1380,1383,1385,1388,1390,1393],{"class":188,"style":189},[186,1364,1207],{"style":200},[186,1366,22],{"style":192},[186,1368,1212],{"style":221},[186,1370,266],{"style":196},[186,1372,1354],{"style":196},[186,1374,272],{"style":192},[186,1376,1377],{"style":192},"import",[186,1379,22],{"style":192},[186,1381,1382],{"style":196},"meta",[186,1384,22],{"style":192},[186,1386,1387],{"style":196},"env",[186,1389,22],{"style":192},[186,1391,1392],{"style":196},"DEV ",[186,1394,778],{"style":196},[186,1396,1397,1399,1401,1403,1405,1407,1409,1411,1413,1415,1417,1419],{"class":188,"style":189},[186,1398,1207],{"style":200},[186,1400,22],{"style":192},[186,1402,1212],{"style":221},[186,1404,266],{"style":196},[186,1406,1354],{"style":196},[186,1408,272],{"style":192},[186,1410,197],{"style":196},[186,1412,468],{"style":196},[186,1414,272],{"style":192},[186,1416,775],{"style":196},[186,1418,930],{"style":196},[186,1420,1421],{"style":353},"\u002F\u002F skip one direction",[11,1423,1424,1425,1428,1429,272,1432,1434,1435,341,1438,1324,1440,1442,1443,1445],{},"The default is ",[15,1426,1427],{},"true",". The object form skips each direction set to ",[15,1430,1431],{},"false",[15,1433,456],{}," (the body), ",[15,1436,1437],{},"params",[15,1439,468],{},[15,1441,82],{},". A per-call ",[15,1444,1354],{}," overrides the client.",[24,1447,1449],{"id":1448},"less-common-cases","Less common cases",[1451,1452,543],"h3",{"id":1453},"status-ranges",[11,1455,1456,1457,1459,1460,1463],{},"When an operation declares a range key such as ",[15,1458,538],{},", the range covers its statuses that have no entry of their own, and ",[15,1461,1462],{},"default"," covers the rest.",[1451,1465,855],{"id":1466},"empty-error-bodies-and-default-responses",[11,1468,1469,1470,1472,1473,22],{},"When a failed call has an empty body, ",[15,1471,82],{}," is ",[15,1474,1331],{},[11,1476,1477,1478,1480,1481,1483,1484,83,1486,1488,1489,1491,1492,1495,1496,1499,1500,1502,1503,1506,1507,22],{},"When the operation declares a ",[15,1479,1462],{}," response, a check on ",[15,1482,86],{}," does not narrow ",[15,1485,65],{},[15,1487,82],{},", because a ",[15,1490,1462],{}," status can be any number. To get the success body with the default ",[15,1493,1494],{},"returnType: 'full'",", call ",[15,1497,1498],{},".unwrap()",", which turns ",[15,1501,82],{}," into a rejection. With ",[15,1504,1505],{},"returnType: 'data'",", the call returns a plain promise without ",[15,1508,1498],{},[1451,1510,1512,1513,1515],{"id":1511},"where-the-throwonerror-default-comes-from","Where the ",[15,1514,33],{}," default comes from",[11,1517,1518,1519,1521,1522,1524,1525,1529,1530,1533],{},"When you set ",[15,1520,874],{},", generated calls ignore it, because each generated function passes its own value: the call's ",[15,1523,33],{},", or else ",[144,1526,1527],{"href":864},[15,1528,867],{},". That value is also the default of the function's ",[15,1531,1532],{},"ThrowOnError"," type parameter.",[1451,1535,1537,1538],{"id":1536},"read-headers-with-returntype-data","Read headers with ",[15,1539,1505],{},[11,1541,1542,1543,1548,1549,1552,1553,1555,1556,1559,1560,22],{},"When the plugin sets ",[144,1544,1546],{"href":1545},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Foptions#returntype",[15,1547,1505],{},", a call resolves to the success body alone. To read a header such as ",[15,1550,1551],{},"ETag",", pass ",[15,1554,21],{}," and call ",[15,1557,1558],{},"result.headers.get('etag')",". For a stream call, see ",[144,1561,1563],{"href":1562},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fserver-sent-events#event-ids-when-you-resume","Event IDs when you resume",[11,1565,1566,1567,1570,1571,1574,1575,22],{},"The query plugins and ",[15,1568,1569],{},"@kubb\u002Fplugin-mcp"," read ",[15,1572,1573],{},"returnType"," too, including a per-operation value from ",[144,1576,1578],{"href":1577},"https:\u002F\u002Fkubb.dev\u002Fdocs\u002F5.x\u002Freference\u002Fplugin-options#override",[15,1579,1580],{},"override",{"title":1582,"searchDepth":1583,"depth":1583,"links":1584},"",5,[1585,1587,1588,1589,1590,1591,1592,1593],{"id":26,"depth":1586,"text":27},2,{"id":160,"depth":1586,"text":161},{"id":519,"depth":1586,"text":520},{"id":716,"depth":1586,"text":717},{"id":858,"depth":1586,"text":859},{"id":980,"depth":1586,"text":981},{"id":1345,"depth":1586,"text":1346},{"id":1448,"depth":1586,"text":1449,"children":1594},[1595,1597,1598,1600],{"id":1453,"depth":1596,"text":543},3,{"id":1466,"depth":1596,"text":855},{"id":1511,"depth":1596,"text":1599},"Where the throwOnError default comes from",{"id":1536,"depth":1596,"text":1601},"Read headers with returnType: 'data'","\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Ferror-handling",1795727684492,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]