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