[{"data":1,"prerenderedAt":918},["ShallowReactive",2],{"navigation":3,"-guide-basics-error":184,"-guide-basics-error-surround":913},[4,91,133,161,168],{"title":5,"path":6,"stem":7,"children":8,"icon":90},"Guide","/guide","1.guide/0.index",[9,12,53,69],{"title":10,"path":6,"stem":7,"icon":11},"Getting Started","pixel:play",{"title":5,"icon":13,"path":14,"stem":15,"children":16,"page":52},"ph:book-open-duotone","/guide/basics","1.guide/1.basics",[17,22,27,32,37,42,47],{"title":18,"path":19,"stem":20,"icon":21},"Request Lifecycle","/guide/basics/lifecycle","1.guide/1.basics/1.lifecycle","icon-park-outline:handle-round",{"title":23,"path":24,"stem":25,"icon":26},"Routing","/guide/basics/routing","1.guide/1.basics/2.routing","solar:routing-bold",{"title":28,"path":29,"stem":30,"icon":31},"Middleware","/guide/basics/middleware","1.guide/1.basics/3.middleware","mdi:middleware-outline",{"title":33,"path":34,"stem":35,"icon":36},"Event Handlers","/guide/basics/handler","1.guide/1.basics/4.handler","mdi:function",{"title":38,"path":39,"stem":40,"icon":41},"Sending Response","/guide/basics/response","1.guide/1.basics/5.response","tabler:json",{"title":43,"path":44,"stem":45,"icon":46},"Error Handling","/guide/basics/error","1.guide/1.basics/6.error","tabler:error-404",{"title":48,"path":49,"stem":50,"icon":51},"Nested Apps","/guide/basics/nested-apps","1.guide/1.basics/7.nested-apps","material-symbols-light:layers-outline",false,{"title":54,"icon":55,"path":56,"stem":57,"children":58,"page":52},"API","material-symbols-light:api-rounded","/guide/api","1.guide/900.api",[59,64],{"title":60,"path":61,"stem":62,"icon":63},"H3","/guide/api/h3","1.guide/900.api/1.h3","material-symbols:bolt-rounded",{"title":65,"path":66,"stem":67,"icon":68},"H3Event","/guide/api/h3event","1.guide/900.api/2.h3event","material-symbols:data-object-rounded",{"title":70,"icon":71,"path":72,"stem":73,"children":74,"page":52},"Advanced","hugeicons:more-01","/guide/advanced","1.guide/901.advanced",[75,80,85],{"title":76,"path":77,"stem":78,"icon":79},"Plugins","/guide/advanced/plugins","1.guide/901.advanced/1.plugins","clarity:plugin-line",{"title":81,"path":82,"stem":83,"icon":84},"WebSockets","/guide/advanced/websocket","1.guide/901.advanced/2.websocket","hugeicons:live-streaming-02",{"title":86,"path":87,"stem":88,"icon":89},"Nightly Builds","/guide/advanced/nightly","1.guide/901.advanced/9.nightly","game-icons:barn-owl","i-ph:book-open-duotone",{"title":92,"path":93,"stem":94,"children":95,"icon":97},"Utils","/utils","2.utils/0.index",[96,98,103,108,113,118,123,128],{"title":92,"path":93,"stem":94,"icon":97},"ph:function-bold",{"title":99,"path":100,"stem":101,"icon":102},"Request","/utils/request","2.utils/1.request","material-symbols-light:input",{"title":104,"path":105,"stem":106,"icon":107},"Response","/utils/response","2.utils/2.response","material-symbols-light:output",{"title":109,"path":110,"stem":111,"icon":112},"Cookie","/utils/cookie","2.utils/3.cookie","material-symbols:cookie-outline",{"title":114,"path":115,"stem":116,"icon":117},"Security","/utils/security","2.utils/4.security","wpf:key-security",{"title":119,"path":120,"stem":121,"icon":122},"Proxy","/utils/proxy","2.utils/5.proxy","arcticons:super-proxy",{"title":124,"path":125,"stem":126,"icon":127},"More utils","/utils/more","2.utils/9.more","mingcute:plus-line",{"title":129,"path":130,"stem":131,"icon":132},"Community","/utils/community","2.utils/99.community","lets-icons:external",{"title":134,"path":135,"stem":136,"children":137,"icon":139},"Examples","/examples","4.examples/0.index",[138,140,145,149,153,157],{"title":134,"path":135,"stem":136,"icon":139},"ph:code",{"title":141,"path":142,"stem":143,"icon":144},"Cookies","/examples/handle-cookie","4.examples/handle-cookie","ph:arrow-right",{"title":146,"path":147,"stem":148,"icon":144},"Sessions","/examples/handle-session","4.examples/handle-session",{"title":150,"path":151,"stem":152,"icon":144},"Static Assets","/examples/serve-static-assets","4.examples/serve-static-assets",{"title":154,"path":155,"stem":156,"icon":144},"Stream Response","/examples/stream-response","4.examples/stream-response",{"title":158,"path":159,"stem":160,"icon":144},"Validate Data","/examples/validate-data","4.examples/validate-data",{"title":162,"path":163,"stem":164,"children":165,"icon":167},"Migration","/migration","5.migration/0.index",[166],{"title":162,"path":163,"stem":164,"icon":167},"icons8:up-round",{"title":169,"path":170,"stem":171,"children":172},"Blog","/blog","99.blog",[173,176,180],{"title":169,"path":170,"stem":174,"icon":175},"99.blog/index","i-lucide-file-text",{"title":177,"path":178,"stem":179,"icon":175},"H3 1.8 - Towards the Edge of the Web","/blog/v1.8","99.blog/1.v1.8",{"title":181,"path":182,"stem":183,"icon":175},"H3 v2 beta","/blog/v2-beta","99.blog/2.v2-beta",{"id":185,"title":43,"body":186,"description":907,"extension":908,"meta":909,"navigation":910,"path":44,"seo":911,"stem":45,"__hash__":912},"content/1.guide/1.basics/6.error.md",{"type":187,"value":188,"toc":899,"icon":46},"minimark",[189,198,206,212,457,464,550,557,615,627,630,643,693,710,714,724,805,814,887,895],[190,191,192,193,197],"p",{},"H3 captures all possible errors during ",[194,195,196],"a",{"href":19},"request lifecycle",".",[199,200,202],"h2",{"id":201},"httperror",[203,204,205],"code",{},"HTTPError",[190,207,208,209,211],{},"You can create and throw HTTP errors using ",[203,210,205],{}," with different syntaxes.",[213,214,219],"pre",{"className":215,"code":216,"language":217,"meta":218,"style":218},"language-js shiki shiki-themes github-light github-dark github-dark","import { HTTPError } from \"h3\";\n\napp.get(\"/error\", (event) => {\n  // Using message and details\n  throw new HTTPError(\"Invalid user input\", { status: 400 });\n\n  // Using HTTPError.status(code)\n  throw HTTPError.status(400, \"Bad Request\");\n\n  // Using single pbject\n  throw new HTTPError({\n    status: 400,\n    statusText: \"Bad Request\",\n    message: \"Invalid user input\",\n    data: { field: \"email\" },\n    body: { date: new Date().toJSON() },\n    headers: {},\n  });\n});\n","js","",[203,220,221,244,251,283,290,317,322,328,352,357,363,375,386,396,406,418,439,445,451],{"__ignoreMap":218},[222,223,226,230,234,237,241],"span",{"class":224,"line":225},"line",1,[222,227,229],{"class":228},"so5gQ","import",[222,231,233],{"class":232},"slsVL"," { HTTPError } ",[222,235,236],{"class":228},"from",[222,238,240],{"class":239},"sfrk1"," \"h3\"",[222,242,243],{"class":232},";\n",[222,245,247],{"class":224,"line":246},2,[222,248,250],{"emptyLinePlaceholder":249},true,"\n",[222,252,254,257,261,264,267,270,274,277,280],{"class":224,"line":253},3,[222,255,256],{"class":232},"app.",[222,258,260],{"class":259},"shcOC","get",[222,262,263],{"class":232},"(",[222,265,266],{"class":239},"\"/error\"",[222,268,269],{"class":232},", (",[222,271,273],{"class":272},"sQHwn","event",[222,275,276],{"class":232},") ",[222,278,279],{"class":228},"=>",[222,281,282],{"class":232}," {\n",[222,284,286],{"class":224,"line":285},4,[222,287,289],{"class":288},"sCsY4","  // Using message and details\n",[222,291,293,296,299,302,304,307,310,314],{"class":224,"line":292},5,[222,294,295],{"class":228},"  throw",[222,297,298],{"class":228}," new",[222,300,301],{"class":259}," HTTPError",[222,303,263],{"class":232},[222,305,306],{"class":239},"\"Invalid user input\"",[222,308,309],{"class":232},", { status: ",[222,311,313],{"class":312},"suiK_","400",[222,315,316],{"class":232}," });\n",[222,318,320],{"class":224,"line":319},6,[222,321,250],{"emptyLinePlaceholder":249},[222,323,325],{"class":224,"line":324},7,[222,326,327],{"class":288},"  // Using HTTPError.status(code)\n",[222,329,331,333,336,339,341,343,346,349],{"class":224,"line":330},8,[222,332,295],{"class":228},[222,334,335],{"class":232}," HTTPError.",[222,337,338],{"class":259},"status",[222,340,263],{"class":232},[222,342,313],{"class":312},[222,344,345],{"class":232},", ",[222,347,348],{"class":239},"\"Bad Request\"",[222,350,351],{"class":232},");\n",[222,353,355],{"class":224,"line":354},9,[222,356,250],{"emptyLinePlaceholder":249},[222,358,360],{"class":224,"line":359},10,[222,361,362],{"class":288},"  // Using single pbject\n",[222,364,366,368,370,372],{"class":224,"line":365},11,[222,367,295],{"class":228},[222,369,298],{"class":228},[222,371,301],{"class":259},[222,373,374],{"class":232},"({\n",[222,376,378,381,383],{"class":224,"line":377},12,[222,379,380],{"class":232},"    status: ",[222,382,313],{"class":312},[222,384,385],{"class":232},",\n",[222,387,389,392,394],{"class":224,"line":388},13,[222,390,391],{"class":232},"    statusText: ",[222,393,348],{"class":239},[222,395,385],{"class":232},[222,397,399,402,404],{"class":224,"line":398},14,[222,400,401],{"class":232},"    message: ",[222,403,306],{"class":239},[222,405,385],{"class":232},[222,407,409,412,415],{"class":224,"line":408},15,[222,410,411],{"class":232},"    data: { field: ",[222,413,414],{"class":239},"\"email\"",[222,416,417],{"class":232}," },\n",[222,419,421,424,427,430,433,436],{"class":224,"line":420},16,[222,422,423],{"class":232},"    body: { date: ",[222,425,426],{"class":228},"new",[222,428,429],{"class":259}," Date",[222,431,432],{"class":232},"().",[222,434,435],{"class":259},"toJSON",[222,437,438],{"class":232},"() },\n",[222,440,442],{"class":224,"line":441},17,[222,443,444],{"class":232},"    headers: {},\n",[222,446,448],{"class":224,"line":447},18,[222,449,450],{"class":232},"  });\n",[222,452,454],{"class":224,"line":453},19,[222,455,456],{"class":232},"});\n",[190,458,459,460,463],{},"This will end the request with ",[203,461,462],{},"400 - Bad Request"," status code and the following JSON response:",[213,465,469],{"className":466,"code":467,"language":468,"meta":218,"style":218},"language-json shiki shiki-themes github-light github-dark github-dark","{\n  \"date\": \"2025-06-05T04:20:00.0Z\",\n  \"status\": 400,\n  \"statusText\": \"Bad Request\",\n  \"message\": \"Invalid user input\",\n  \"data\": {\n    \"field\": \"email\"\n  }\n}\n","json",[203,470,471,476,489,500,511,522,530,540,545],{"__ignoreMap":218},[222,472,473],{"class":224,"line":225},[222,474,475],{"class":232},"{\n",[222,477,478,481,484,487],{"class":224,"line":246},[222,479,480],{"class":312},"  \"date\"",[222,482,483],{"class":232},": ",[222,485,486],{"class":239},"\"2025-06-05T04:20:00.0Z\"",[222,488,385],{"class":232},[222,490,491,494,496,498],{"class":224,"line":253},[222,492,493],{"class":312},"  \"status\"",[222,495,483],{"class":232},[222,497,313],{"class":312},[222,499,385],{"class":232},[222,501,502,505,507,509],{"class":224,"line":285},[222,503,504],{"class":312},"  \"statusText\"",[222,506,483],{"class":232},[222,508,348],{"class":239},[222,510,385],{"class":232},[222,512,513,516,518,520],{"class":224,"line":292},[222,514,515],{"class":312},"  \"message\"",[222,517,483],{"class":232},[222,519,306],{"class":239},[222,521,385],{"class":232},[222,523,524,527],{"class":224,"line":319},[222,525,526],{"class":312},"  \"data\"",[222,528,529],{"class":232},": {\n",[222,531,532,535,537],{"class":224,"line":324},[222,533,534],{"class":312},"    \"field\"",[222,536,483],{"class":232},[222,538,539],{"class":239},"\"email\"\n",[222,541,542],{"class":224,"line":330},[222,543,544],{"class":232},"  }\n",[222,546,547],{"class":224,"line":354},[222,548,549],{"class":232},"}\n",[551,552,554,556],"h3",{"id":553},"httperror-fields",[203,555,205],{}," Fields",[558,559,560,566,572,578,587,593,599,605],"ul",{},[561,562,563,565],"li",{},[203,564,338],{},": HTTP status code in the range 200–599.",[561,567,568,571],{},[203,569,570],{},"statusText",": HTTP status text to be sent in the response header.",[561,573,574,577],{},[203,575,576],{},"message",": Error message to be included in the JSON body.",[561,579,580,583,584,586],{},[203,581,582],{},"data",": Additional data to be attached under the ",[203,585,582],{}," key in the error JSON body.",[561,588,589,592],{},[203,590,591],{},"body",": Additional top-level properties to be attached in the error JSON body.",[561,594,595,598],{},[203,596,597],{},"headers",": Additional HTTP headers to be sent in the error response.",[561,600,601,604],{},[203,602,603],{},"cause",": The original error object that caused this error, useful for tracing and debugging.",[561,606,607,610,611,197],{},[203,608,609],{},"unhandled",": Indicates whether the error was thrown for unknown reasons. See ",[194,612,614],{"href":613},"#unhandled-errors","Unhandled Errors",[616,617,618],"important",{},[190,619,620,621,623,624,626],{},"\nError ",[203,622,570],{}," should be short (max 512 to 1024 characters) and only include tab, spaces or visible ASCII characters and extended characters (byte value 128–255). Prefer ",[203,625,576],{}," in JSON body for extended message.",[199,628,614],{"id":629},"unhandled-errors",[190,631,632,633,635,636,638,639,642],{},"Any error that occurs during calling ",[194,634,196],{"href":19}," without using ",[203,637,205],{}," will be processed as an ",[640,641,609],"em",{}," error.",[213,644,646],{"className":215,"code":645,"language":217,"meta":218,"style":218},"app.get(\"/error\", (event) => {\n  // This will cause an unhandled error.\n  throw new Error(\"Something went wrong\");\n});\n",[203,647,648,668,673,689],{"__ignoreMap":218},[222,649,650,652,654,656,658,660,662,664,666],{"class":224,"line":225},[222,651,256],{"class":232},[222,653,260],{"class":259},[222,655,263],{"class":232},[222,657,266],{"class":239},[222,659,269],{"class":232},[222,661,273],{"class":272},[222,663,276],{"class":232},[222,665,279],{"class":228},[222,667,282],{"class":232},[222,669,670],{"class":224,"line":246},[222,671,672],{"class":288},"  // This will cause an unhandled error.\n",[222,674,675,677,679,682,684,687],{"class":224,"line":253},[222,676,295],{"class":228},[222,678,298],{"class":228},[222,680,681],{"class":259}," Error",[222,683,263],{"class":232},[222,685,686],{"class":239},"\"Something went wrong\"",[222,688,351],{"class":232},[222,690,691],{"class":224,"line":285},[222,692,456],{"class":232},[694,695,696],"tip",{},[190,697,698,699,345,701,345,703,706,707,709],{},"\nFor enhanced security, H3 hides certain fields of unhandled errors (",[203,700,582],{},[203,702,591],{},[203,704,705],{},"stack"," and ",[203,708,576],{},") in JSON response.",[199,711,713],{"id":712},"catching-errors","Catching Errors",[190,715,716,717,723],{},"Using global ",[194,718,720],{"href":719},"/guide/api/h3#global-hooks",[203,721,722],{},"onError"," hook:",[213,725,727],{"className":215,"code":726,"language":217,"meta":218,"style":218},"import { H3, onError } from \"h3\";\n\n// Globally handling errors\nconst app = new H3({\n  onError: (error) => {\n    console.error(error);\n  },\n});\n",[203,728,729,742,746,751,769,786,796,801],{"__ignoreMap":218},[222,730,731,733,736,738,740],{"class":224,"line":225},[222,732,229],{"class":228},[222,734,735],{"class":232}," { H3, onError } ",[222,737,236],{"class":228},[222,739,240],{"class":239},[222,741,243],{"class":232},[222,743,744],{"class":224,"line":246},[222,745,250],{"emptyLinePlaceholder":249},[222,747,748],{"class":224,"line":253},[222,749,750],{"class":288},"// Globally handling errors\n",[222,752,753,756,759,762,764,767],{"class":224,"line":285},[222,754,755],{"class":228},"const",[222,757,758],{"class":312}," app",[222,760,761],{"class":228}," =",[222,763,298],{"class":228},[222,765,766],{"class":259}," H3",[222,768,374],{"class":232},[222,770,771,774,777,780,782,784],{"class":224,"line":292},[222,772,773],{"class":259},"  onError",[222,775,776],{"class":232},": (",[222,778,779],{"class":272},"error",[222,781,276],{"class":232},[222,783,279],{"class":228},[222,785,282],{"class":232},[222,787,788,791,793],{"class":224,"line":319},[222,789,790],{"class":232},"    console.",[222,792,779],{"class":259},[222,794,795],{"class":232},"(error);\n",[222,797,798],{"class":224,"line":324},[222,799,800],{"class":232},"  },\n",[222,802,803],{"class":224,"line":330},[222,804,456],{"class":232},[190,806,807,808,813],{},"Using ",[194,809,810,812],{"href":29},[203,811,722],{}," middleware"," to catch errors.",[213,815,817],{"className":215,"code":816,"language":217,"meta":218,"style":218},"import { onError } from \"h3\";\n\n// Handling errors using middleware\napp.use(\n  onError(event, (event, error) => {\n    console.error(error);\n  }),\n);\n",[203,818,819,832,836,841,851,870,878,883],{"__ignoreMap":218},[222,820,821,823,826,828,830],{"class":224,"line":225},[222,822,229],{"class":228},[222,824,825],{"class":232}," { onError } ",[222,827,236],{"class":228},[222,829,240],{"class":239},[222,831,243],{"class":232},[222,833,834],{"class":224,"line":246},[222,835,250],{"emptyLinePlaceholder":249},[222,837,838],{"class":224,"line":253},[222,839,840],{"class":288},"// Handling errors using middleware\n",[222,842,843,845,848],{"class":224,"line":285},[222,844,256],{"class":232},[222,846,847],{"class":259},"use",[222,849,850],{"class":232},"(\n",[222,852,853,855,858,860,862,864,866,868],{"class":224,"line":292},[222,854,773],{"class":259},[222,856,857],{"class":232},"(event, (",[222,859,273],{"class":272},[222,861,345],{"class":232},[222,863,779],{"class":272},[222,865,276],{"class":232},[222,867,279],{"class":228},[222,869,282],{"class":232},[222,871,872,874,876],{"class":224,"line":319},[222,873,790],{"class":232},[222,875,779],{"class":259},[222,877,795],{"class":232},[222,879,880],{"class":224,"line":324},[222,881,882],{"class":232},"  }),\n",[222,884,885],{"class":224,"line":330},[222,886,351],{"class":232},[694,888,889],{},[190,890,891,892,894],{},"\nWhen using nested apps, global hooks of sub-apps will not be called. Therefore it is better to use ",[203,893,722],{}," middleware.",[896,897,898],"style",{},"html pre.shiki code .so5gQ, html code.shiki .so5gQ{--shiki-light:#D73A49;--shiki-default:#F97583;--shiki-dark:#F97583}html pre.shiki code .slsVL, html code.shiki .slsVL{--shiki-light:#24292E;--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8}html pre.shiki code .sfrk1, html code.shiki .sfrk1{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF}html pre.shiki code .shcOC, html code.shiki .shcOC{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0}html pre.shiki code .sQHwn, html code.shiki .sQHwn{--shiki-light:#E36209;--shiki-default:#FFAB70;--shiki-dark:#FFAB70}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .suiK_, html code.shiki .suiK_{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":218,"searchDepth":246,"depth":246,"links":900},[901,905,906],{"id":201,"depth":246,"text":205,"children":902},[903],{"id":553,"depth":253,"text":904},"HTTPError Fields",{"id":629,"depth":246,"text":614},{"id":712,"depth":246,"text":713},"Send errors by throwing an HTTPError.","md",{"icon":46},{"icon":46},{"title":43,"description":907},"eIurDxtrQBlBoO0wZ1G3tutMSsgL_AiGUPRJwEHvfDc",[914,916],{"title":38,"path":39,"stem":40,"description":915,"icon":41,"children":-1},"H3 automatically converts any returned value into a web response.",{"title":48,"path":49,"stem":50,"description":917,"icon":51,"children":-1},"H3 has a native mount method for adding nested sub-apps to the main instance.",1768646387274]