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