[{"data":1,"prerenderedAt":2310},["ShallowReactive",2],{"navigation_docs":3,"-rpc-server-error-handling":399},[4,162,346],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":24},"RPC","icon-park-outline:lightning","\u002Frpc","01.rpc",[10,25,63,77,102,136],{"title":11,"icon":12,"redirect":7,"path":13,"stem":14,"children":15,"page":24},"Introduction","icon-park-outline:home","\u002Frpc\u002Fintroduction","01.rpc\u002F01.introduction",[16,20],{"title":17,"path":18,"stem":19},"Quick Start","\u002Frpc\u002Fintroduction\u002Fquick-start","01.rpc\u002F01.introduction\u002F02.quick-start",{"title":21,"path":22,"stem":23},"Manual Install","\u002Frpc\u002Fintroduction\u002Fmanual-install","01.rpc\u002F01.introduction\u002F03.manual-install",false,{"title":26,"icon":27,"path":28,"stem":29,"children":30,"page":24},"Server","icon-park-outline:server","\u002Frpc\u002Fserver","01.rpc\u002F02.server",[31,35,39,43,47,51,55,59],{"title":32,"path":33,"stem":34},"Routes","\u002Frpc\u002Fserver\u002Froutes","01.rpc\u002F02.server\u002F01.routes",{"title":36,"path":37,"stem":38},"Middleware","\u002Frpc\u002Fserver\u002Fmiddleware","01.rpc\u002F02.server\u002F02.middleware",{"title":40,"path":41,"stem":42},"Call Context","\u002Frpc\u002Fserver\u002Fcall-context","01.rpc\u002F02.server\u002F03.call-context",{"title":44,"path":45,"stem":46},"Headers","\u002Frpc\u002Fserver\u002Fheaders","01.rpc\u002F02.server\u002F04.headers",{"title":48,"path":49,"stem":50},"Error Handling","\u002Frpc\u002Fserver\u002Ferror-handling","01.rpc\u002F02.server\u002F05.error-handling",{"title":52,"path":53,"stem":54},"Validation","\u002Frpc\u002Fserver\u002Fvalidation","01.rpc\u002F02.server\u002F06.validation",{"title":56,"path":57,"stem":58},"JSON Round Trip","\u002Frpc\u002Fserver\u002Fjson-round-trip","01.rpc\u002F02.server\u002F07.json-round-trip",{"title":60,"path":61,"stem":62},"Drizzle Tables","\u002Frpc\u002Fserver\u002Fdrizzle-tables","01.rpc\u002F02.server\u002F08.drizzle-tables",{"title":64,"icon":65,"path":66,"stem":67,"children":68,"page":24},"Middlewares","icon-park-outline:link-one","\u002Frpc\u002Fmiddlewares","01.rpc\u002F03.middlewares",[69,73],{"title":70,"path":71,"stem":72},"fetchMetadata","\u002Frpc\u002Fmiddlewares\u002Ffetch-metadata","01.rpc\u002F03.middlewares\u002F01.fetch-metadata",{"title":74,"path":75,"stem":76},"syncRoutes","\u002Frpc\u002Fmiddlewares\u002Fsync-routes","01.rpc\u002F03.middlewares\u002F02.sync-routes",{"title":78,"icon":79,"path":80,"stem":81,"children":82,"page":24},"Client","icon-park-outline:computer","\u002Frpc\u002Fclient","01.rpc\u002F04.client",[83,87,91,94,98],{"title":84,"path":85,"stem":86},"Client Overview","\u002Frpc\u002Fclient\u002Fclient-overview","01.rpc\u002F04.client\u002F00.client-overview",{"title":88,"path":89,"stem":90},"Client Middleware","\u002Frpc\u002Fclient\u002Fclient-middleware","01.rpc\u002F04.client\u002F01.client-middleware",{"title":48,"path":92,"stem":93},"\u002Frpc\u002Fclient\u002Ferror-handling","01.rpc\u002F04.client\u002F02.error-handling",{"title":95,"path":96,"stem":97},"Batch Requests","\u002Frpc\u002Fclient\u002Fbatch","01.rpc\u002F04.client\u002F03.batch",{"title":99,"path":100,"stem":101},"Cancellation & Timeouts","\u002Frpc\u002Fclient\u002Fcancellation-timeouts","01.rpc\u002F04.client\u002F04.cancellation-timeouts",{"title":103,"redirect":104,"icon":105,"path":106,"stem":107,"children":108,"page":24},"Platforms","\u002Frpc\u002Fplatforms\u002Fnode-js","icon-park-outline:play","\u002Frpc\u002Fplatforms","01.rpc\u002F06.platforms",[109,112,116,120,124,128,132],{"title":110,"path":104,"stem":111},"Node.js","01.rpc\u002F06.platforms\u002F01.node-js",{"title":113,"path":114,"stem":115},"Bun","\u002Frpc\u002Fplatforms\u002Fbun","01.rpc\u002F06.platforms\u002F02.bun",{"title":117,"path":118,"stem":119},"AWS Lambda","\u002Frpc\u002Fplatforms\u002Faws-lambda","01.rpc\u002F06.platforms\u002F03.aws-lambda",{"title":121,"path":122,"stem":123},"Google Cloud Functions","\u002Frpc\u002Fplatforms\u002Fgoogle-cloud-functions","01.rpc\u002F06.platforms\u002F04.google-cloud-functions",{"title":125,"path":126,"stem":127},"Cloudflare Workers","\u002Frpc\u002Fplatforms\u002Fcloudflare","01.rpc\u002F06.platforms\u002F05.cloudflare",{"title":129,"path":130,"stem":131},"Vercel","\u002Frpc\u002Fplatforms\u002Fvercel","01.rpc\u002F06.platforms\u002F06.vercel",{"title":133,"path":134,"stem":135},"uWebSockets.js","\u002Frpc\u002Fplatforms\u002Fuwebsockets","01.rpc\u002F06.platforms\u002F07.uwebsockets",{"title":137,"icon":138,"path":139,"stem":140,"children":141,"page":24},"Devtools","icon-park-outline:tool","\u002Frpc\u002Fdevtools","01.rpc\u002F07.devtools",[142,146,150,154,158],{"title":143,"path":144,"stem":145},"Linter","\u002Frpc\u002Fdevtools\u002Flinter","01.rpc\u002F07.devtools\u002F01.linter",{"title":147,"path":148,"stem":149},"Vite","\u002Frpc\u002Fdevtools\u002Fvite","01.rpc\u002F07.devtools\u002F02.vite",{"title":151,"path":152,"stem":153},"Next.js","\u002Frpc\u002Fdevtools\u002Fnextjs","01.rpc\u002F07.devtools\u002F03.nextjs",{"title":155,"path":156,"stem":157},"CLI","\u002Frpc\u002Fdevtools\u002Fcli","01.rpc\u002F07.devtools\u002F04.cli",{"title":159,"path":160,"stem":161},"API Types","\u002Frpc\u002Fdevtools\u002Fapi-types","01.rpc\u002F07.devtools\u002F05.api-types",{"title":163,"icon":164,"path":165,"stem":166,"children":167,"page":24},"RunTypes","i-lucide-braces","\u002Fruntypes","02.runtypes",[168,184,224,254,268,290,332],{"title":11,"icon":169,"redirect":165,"path":170,"stem":171,"children":172,"page":24},"i-lucide-rocket","\u002Fruntypes\u002Fintroduction","02.runtypes\u002F01.introduction",[173,177,180],{"title":174,"path":175,"stem":176},"Built on typescript-go","\u002Fruntypes\u002Fintroduction\u002Fbuilt-on-typescript-go","02.runtypes\u002F01.introduction\u002F02.built-on-typescript-go",{"title":17,"path":178,"stem":179},"\u002Fruntypes\u002Fintroduction\u002Fquick-start","02.runtypes\u002F01.introduction\u002F03.quick-start",{"title":181,"path":182,"stem":183},"Configuration","\u002Fruntypes\u002Fintroduction\u002Fconfiguration","02.runtypes\u002F01.introduction\u002F04.configuration",{"title":185,"icon":186,"redirect":187,"path":188,"stem":189,"children":190,"page":24},"Guide","i-lucide-book-open","\u002Fruntypes\u002Fguide\u002Ftype-builders","\u002Fruntypes\u002Fguide","02.runtypes\u002F02.guide",[191,194,198,201,204,208,212,216,220],{"title":192,"path":187,"stem":193},"Types vs Type Builders","02.runtypes\u002F02.guide\u002F01.type-builders",{"title":195,"path":196,"stem":197},"Reflection","\u002Fruntypes\u002Fguide\u002Freflection","02.runtypes\u002F02.guide\u002F02.reflection",{"title":52,"path":199,"stem":200},"\u002Fruntypes\u002Fguide\u002Fvalidation","02.runtypes\u002F02.guide\u002F03.validation",{"title":56,"path":202,"stem":203},"\u002Fruntypes\u002Fguide\u002Fjson-round-trip","02.runtypes\u002F02.guide\u002F04.json-round-trip",{"title":205,"path":206,"stem":207},"Data Mocking","\u002Fruntypes\u002Fguide\u002Fmocking","02.runtypes\u002F02.guide\u002F07.mocking",{"title":209,"path":210,"stem":211},"JSON Schemas","\u002Fruntypes\u002Fguide\u002Fjson-schemas","02.runtypes\u002F02.guide\u002F08.json-schemas",{"title":213,"path":214,"stem":215},"Pure Functions","\u002Fruntypes\u002Fguide\u002Fpure-functions","02.runtypes\u002F02.guide\u002F09.pure-functions",{"title":217,"path":218,"stem":219},"Compiler Markers","\u002Fruntypes\u002Fguide\u002Fcompiler-markers","02.runtypes\u002F02.guide\u002F10.compiler-markers",{"title":221,"path":222,"stem":223},"All Compiled Functions","\u002Fruntypes\u002Fguide\u002Fall-compiled-functions","02.runtypes\u002F02.guide\u002F11.all-compiled-functions",{"title":225,"icon":226,"redirect":227,"path":228,"stem":229,"children":230,"page":24},"Type Formats","i-lucide-shapes","\u002Fruntypes\u002Ftype-formats\u002Foverview","\u002Fruntypes\u002Ftype-formats","02.runtypes\u002F03.type-formats",[231,234,238,242,246,250],{"title":232,"path":227,"stem":233},"Overview","02.runtypes\u002F03.type-formats\u002F01.overview",{"title":235,"path":236,"stem":237},"String Formats","\u002Fruntypes\u002Ftype-formats\u002Fstring","02.runtypes\u002F03.type-formats\u002F02.string",{"title":239,"path":240,"stem":241},"Number Formats","\u002Fruntypes\u002Ftype-formats\u002Fnumber","02.runtypes\u002F03.type-formats\u002F03.number",{"title":243,"path":244,"stem":245},"BigInt Formats","\u002Fruntypes\u002Ftype-formats\u002Fbigint","02.runtypes\u002F03.type-formats\u002F04.bigint",{"title":247,"path":248,"stem":249},"Date and Time Formats","\u002Fruntypes\u002Ftype-formats\u002Fdate-time","02.runtypes\u002F03.type-formats\u002F05.date-time",{"title":251,"path":252,"stem":253},"Collection Formats","\u002Fruntypes\u002Ftype-formats\u002Fcollections","02.runtypes\u002F03.type-formats\u002F06.collections",{"title":255,"icon":256,"redirect":257,"path":258,"stem":259,"children":260,"page":24},"Tooling","i-lucide-wrench","\u002Fruntypes\u002Ftooling\u002Flinting","\u002Fruntypes\u002Ftooling","02.runtypes\u002F04.tooling",[261,264],{"title":262,"path":257,"stem":263},"Linting","02.runtypes\u002F04.tooling\u002F01.linting",{"title":265,"path":266,"stem":267},"Source Conversion","\u002Fruntypes\u002Ftooling\u002Fsource-conversion","02.runtypes\u002F04.tooling\u002F02.source-conversion",{"title":269,"icon":270,"redirect":271,"path":272,"stem":273,"children":274,"page":24},"AI Integration","i-lucide-sparkles","\u002Fruntypes\u002Fai-integration\u002Fworkflow-and-commands","\u002Fruntypes\u002Fai-integration","02.runtypes\u002F05.ai-integration",[275,278,282,286],{"title":276,"path":271,"stem":277},"AI Workflow","02.runtypes\u002F05.ai-integration\u002F01.workflow-and-commands",{"title":279,"path":280,"stem":281},"FriendlyText","\u002Fruntypes\u002Fai-integration\u002Ffriendly-text","02.runtypes\u002F05.ai-integration\u002F02.friendly-text",{"title":283,"path":284,"stem":285},"MockData","\u002Fruntypes\u002Fai-integration\u002Fmock-data","02.runtypes\u002F05.ai-integration\u002F03.mock-data",{"title":287,"path":288,"stem":289},"Translations (i18n)","\u002Fruntypes\u002Fai-integration\u002Fi18n","02.runtypes\u002F05.ai-integration\u002F04.i18n",{"title":291,"icon":292,"redirect":293,"path":294,"stem":295,"children":296,"page":24},"Drizzle ORM","i-lineicons-drizzle","\u002Fruntypes\u002Fdrizzle-orm\u002Fdrizzle-overview","\u002Fruntypes\u002Fdrizzle-orm","02.runtypes\u002F06.drizzle-orm",[297,300,304,308,312,316,320,324,328],{"title":298,"path":293,"stem":299},"Drizzle Overview","02.runtypes\u002F06.drizzle-orm\u002F00.drizzle-overview",{"title":301,"path":302,"stem":303},"Column Formats","\u002Fruntypes\u002Fdrizzle-orm\u002Fcolumn-formats","02.runtypes\u002F06.drizzle-orm\u002F01.column-formats",{"title":305,"path":306,"stem":307},"Views","\u002Fruntypes\u002Fdrizzle-orm\u002Fviews","02.runtypes\u002F06.drizzle-orm\u002F02.views",{"title":309,"path":310,"stem":311},"Indexes and Constraints","\u002Fruntypes\u002Fdrizzle-orm\u002Fconstraints","02.runtypes\u002F06.drizzle-orm\u002F03.constraints",{"title":313,"path":314,"stem":315},"Row Level Security","\u002Fruntypes\u002Fdrizzle-orm\u002Frow-level-security","02.runtypes\u002F06.drizzle-orm\u002F04.row-level-security",{"title":317,"path":318,"stem":319},"Relations","\u002Fruntypes\u002Fdrizzle-orm\u002Frelations","02.runtypes\u002F06.drizzle-orm\u002F05.relations",{"title":321,"path":322,"stem":323},"The Schema File","\u002Fruntypes\u002Fdrizzle-orm\u002Fschema-file","02.runtypes\u002F06.drizzle-orm\u002F06.schema-file",{"title":325,"path":326,"stem":327},"Migrate an Existing Schema","\u002Fruntypes\u002Fdrizzle-orm\u002Fmigrate-an-existing-schema","02.runtypes\u002F06.drizzle-orm\u002F07.migrate-an-existing-schema",{"title":329,"path":330,"stem":331},"Cloudflare D1 and Durable Objects","\u002Fruntypes\u002Fdrizzle-orm\u002Fcloudflare-storage","02.runtypes\u002F06.drizzle-orm\u002F08.cloudflare-storage",{"title":333,"icon":334,"redirect":335,"path":336,"stem":337,"children":338,"page":24},"Diagnostics","i-lucide-triangle-alert","\u002Fruntypes\u002Fdiagnostics\u002Ferror-levels","\u002Fruntypes\u002Fdiagnostics","02.runtypes\u002F08.diagnostics",[339,342],{"title":340,"path":335,"stem":341},"Error Levels","02.runtypes\u002F08.diagnostics\u002F01.error-levels",{"title":343,"path":344,"stem":345},"All Diagnostics","\u002Fruntypes\u002Fdiagnostics\u002Fall-diagnostics","02.runtypes\u002F08.diagnostics\u002F02.all-diagnostics",{"title":347,"icon":348,"path":349,"stem":350,"children":351,"page":24},"Benchmarks","i-lucide-gauge","\u002Fbenchmarks","03.benchmarks",[352,372],{"title":5,"icon":6,"redirect":353,"path":354,"stem":355,"children":356,"page":24},"\u002Fbenchmarks\u002Frpc\u002Fhello-world","\u002Fbenchmarks\u002Frpc","03.benchmarks\u002F02.rpc",[357,360,364,368],{"title":358,"path":353,"stem":359},"Hello World","03.benchmarks\u002F02.rpc\u002F01.hello-world",{"title":361,"path":362,"stem":363},"Light Validation","\u002Fbenchmarks\u002Frpc\u002Flight-validation","03.benchmarks\u002F02.rpc\u002F02.light-validation",{"title":365,"path":366,"stem":367},"Heavy Validation","\u002Fbenchmarks\u002Frpc\u002Fheavy-validation","03.benchmarks\u002F02.rpc\u002F03.heavy-validation",{"title":369,"path":370,"stem":371},"Payload Sizes","\u002Fbenchmarks\u002Frpc\u002Fpayload-sizes","03.benchmarks\u002F02.rpc\u002F04.payload-sizes",{"title":163,"icon":164,"redirect":373,"path":374,"stem":375,"children":376,"page":24},"\u002Fbenchmarks\u002Fruntypes\u002Fis-valid","\u002Fbenchmarks\u002Fruntypes","03.benchmarks\u002F03.runtypes",[377,380,384,388,392,395],{"title":378,"path":373,"stem":379},"Is Valid","03.benchmarks\u002F03.runtypes\u002F01.is-valid",{"title":381,"path":382,"stem":383},"Is Valid Formats","\u002Fbenchmarks\u002Fruntypes\u002Fis-valid-formats","03.benchmarks\u002F03.runtypes\u002F02.is-valid-formats",{"title":385,"path":386,"stem":387},"Get Errors","\u002Fbenchmarks\u002Fruntypes\u002Fget-errors","03.benchmarks\u002F03.runtypes\u002F03.get-errors",{"title":389,"path":390,"stem":391},"Get Errors Formats","\u002Fbenchmarks\u002Fruntypes\u002Fget-errors-formats","03.benchmarks\u002F03.runtypes\u002F04.get-errors-formats",{"title":56,"path":393,"stem":394},"\u002Fbenchmarks\u002Fruntypes\u002Fjson-round-trip","03.benchmarks\u002F03.runtypes\u002F05.json-round-trip",{"title":396,"path":397,"stem":398},"Type Checking","\u002Fbenchmarks\u002Fruntypes\u002Ftype-checking","03.benchmarks\u002F03.runtypes\u002F07.type-checking",{"id":400,"title":48,"body":401,"description":2304,"extension":2305,"links":2306,"meta":2307,"navigation":1095,"path":49,"seo":2308,"stem":50,"__hash__":2309},"docs\u002F01.rpc\u002F02.server\u002F05.error-handling.md",{"type":402,"value":403},"minimark",[404,413,477,482,497,773,777,781,795,970,986,990,1003,1007,1014,1708,1712,1724,2008,2014,2034,2038,2060,2266,2279,2285,2289,2300],[405,406,407,408,412],"p",{},"mion uses ",[409,410,411],"code",{},"RpcError"," for every error in routes and middleware. How you raise it decides whether the client gets it typed and whether the rest of the chain runs.",[414,415,416,432],"table",{},[417,418,419],"thead",{},[420,421,422,426,429],"tr",{},[423,424,425],"th",{},"What you write",[423,427,428],{},"Typed on the client",[423,430,431],{},"The rest of the chain",[433,434,435,449,461],"tbody",{},[420,436,437,443,446],{},[438,439,440],"td",{},[409,441,442],{},"return new RpcError(...)",[438,444,445],{},"Yes, as the route's error or at the middleware's path",[438,447,448],{},"Keeps running",[420,450,451,456,458],{},[438,452,453],{},[409,454,455],{},"return new FatalError(...)",[438,457,445],{},[438,459,460],{},"Stops",[420,462,463,469,475],{},[438,464,465,468],{},[409,466,467],{},"throw"," anything",[438,470,471,472],{},"No, only the public message in ",[409,473,474],{},"@thrownErrors",[438,476,460],{},[478,479,481],"h2",{"id":480},"return-errors","Return Errors",[405,483,484,488,489,492,493,496],{},[485,486,487],"strong",{},"Return application errors."," A returned error is part of the function signature, so the client knows every error type a route can answer, its ",[409,490,491],{},"errorData"," included. With several error types, the client gets a discriminated union of all of them. A returned error keeps the chain running, so one route answering ",[409,494,495],{},"user-not-found"," does not drop the other routes in the same request.",[498,499,504],"pre",{"className":500,"code":501,"language":502,"meta":503,"style":503},"language-ts shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","export const getPet = mion.route(\n  async (ctx, id: string): Promise\u003CPet | RpcError\u003C'pet-not-found'>> => {\n    const pet = await myApp.db.getPet(id);\n    if (!pet) {\n      return new RpcError({\n        publicMessage: `Pet with id ${id} can't be found`,\n        type: 'pet-not-found',\n      });\n    }\n    return pet;\n  }\n) satisfies Route;\n","ts","",[409,505,506,540,604,645,665,680,711,728,738,744,754,760],{"__ignoreMap":503},[507,508,511,515,519,523,527,530,533,537],"span",{"class":509,"line":510},"line",1,[507,512,514],{"class":513},"s7zQu","export",[507,516,518],{"class":517},"spNyl"," const",[507,520,522],{"class":521},"sTEyZ"," getPet ",[507,524,526],{"class":525},"sMK4o","=",[507,528,529],{"class":521}," mion",[507,531,532],{"class":525},".",[507,534,536],{"class":535},"s2Zo4","route",[507,538,539],{"class":521},"(\n",[507,541,543,546,549,553,556,559,562,566,569,572,575,578,581,584,586,589,593,595,598,601],{"class":509,"line":542},2,[507,544,545],{"class":517},"  async",[507,547,548],{"class":525}," (",[507,550,552],{"class":551},"sHdIc","ctx",[507,554,555],{"class":525},",",[507,557,558],{"class":551}," id",[507,560,561],{"class":525},":",[507,563,565],{"class":564},"sBMFI"," string",[507,567,568],{"class":525},"):",[507,570,571],{"class":564}," Promise",[507,573,574],{"class":525},"\u003C",[507,576,577],{"class":564},"Pet",[507,579,580],{"class":525}," |",[507,582,583],{"class":564}," RpcError",[507,585,574],{"class":525},[507,587,588],{"class":525},"'",[507,590,592],{"class":591},"sfazB","pet-not-found",[507,594,588],{"class":525},[507,596,597],{"class":525},">>",[507,599,600],{"class":517}," =>",[507,602,603],{"class":525}," {\n",[507,605,607,610,613,616,619,622,624,627,629,632,636,639,642],{"class":509,"line":606},3,[507,608,609],{"class":517},"    const",[507,611,612],{"class":521}," pet",[507,614,615],{"class":525}," =",[507,617,618],{"class":513}," await",[507,620,621],{"class":521}," myApp",[507,623,532],{"class":525},[507,625,626],{"class":521},"db",[507,628,532],{"class":525},[507,630,631],{"class":535},"getPet",[507,633,635],{"class":634},"swJcz","(",[507,637,638],{"class":521},"id",[507,640,641],{"class":634},")",[507,643,644],{"class":525},";\n",[507,646,648,651,653,656,659,662],{"class":509,"line":647},4,[507,649,650],{"class":513},"    if",[507,652,548],{"class":634},[507,654,655],{"class":525},"!",[507,657,658],{"class":521},"pet",[507,660,661],{"class":634},") ",[507,663,664],{"class":525},"{\n",[507,666,668,671,674,676,678],{"class":509,"line":667},5,[507,669,670],{"class":513},"      return",[507,672,673],{"class":525}," new",[507,675,583],{"class":535},[507,677,635],{"class":634},[507,679,664],{"class":525},[507,681,683,686,688,691,694,697,699,702,705,708],{"class":509,"line":682},6,[507,684,685],{"class":634},"        publicMessage",[507,687,561],{"class":525},[507,689,690],{"class":525}," `",[507,692,693],{"class":591},"Pet with id ",[507,695,696],{"class":525},"${",[507,698,638],{"class":521},[507,700,701],{"class":525},"}",[507,703,704],{"class":591}," can't be found",[507,706,707],{"class":525},"`",[507,709,710],{"class":525},",\n",[507,712,714,717,719,722,724,726],{"class":509,"line":713},7,[507,715,716],{"class":634},"        type",[507,718,561],{"class":525},[507,720,721],{"class":525}," '",[507,723,592],{"class":591},[507,725,588],{"class":525},[507,727,710],{"class":525},[507,729,731,734,736],{"class":509,"line":730},8,[507,732,733],{"class":525},"      }",[507,735,641],{"class":634},[507,737,644],{"class":525},[507,739,741],{"class":509,"line":740},9,[507,742,743],{"class":525},"    }\n",[507,745,747,750,752],{"class":509,"line":746},10,[507,748,749],{"class":513},"    return",[507,751,612],{"class":521},[507,753,644],{"class":525},[507,755,757],{"class":509,"line":756},11,[507,758,759],{"class":525},"  }\n",[507,761,763,765,768,771],{"class":509,"line":762},12,[507,764,661],{"class":521},[507,766,767],{"class":513},"satisfies",[507,769,770],{"class":564}," Route",[507,772,644],{"class":525},[774,775,776],"tip",{},"A middleware can return a typed error without blocking, such as an expired session on a route that still works for guests.",[478,778,780],{"id":779},"stopping-the-request","Stopping the Request",[405,782,783,784,787,788,790,791,794],{},"Return a ",[409,785,786],{},"FatalError"," when an error must also stop the request, like a failed auth check in a middleware. It is an ",[409,789,411],{},", so it stays in the signature and reaches the client typed. Nothing after it runs except the middleware with ",[409,792,793],{},"alwaysRun",", and in a batch the routes after it are skipped.",[498,796,798],{"className":500,"code":797,"language":502,"meta":503,"style":503},"\u002F\u002F ends the request: the route behind this middleware never runs\nexport const auth = mion.middleware(\n  (ctx): void | FatalError\u003C'not-authorized'> => {\n    if (!myApp.auth.getSessionUser(ctx.request.headers.get('cookie')))\n      return new FatalError({\n        publicMessage: 'Not Authorized',\n        type: 'not-authorized',\n      });\n  }\n);\n",[409,799,800,806,826,859,911,923,938,952,960,964],{"__ignoreMap":503},[507,801,802],{"class":509,"line":510},[507,803,805],{"class":804},"sHwdD","\u002F\u002F ends the request: the route behind this middleware never runs\n",[507,807,808,810,812,815,817,819,821,824],{"class":509,"line":542},[507,809,514],{"class":513},[507,811,518],{"class":517},[507,813,814],{"class":521}," auth ",[507,816,526],{"class":525},[507,818,529],{"class":521},[507,820,532],{"class":525},[507,822,823],{"class":535},"middleware",[507,825,539],{"class":521},[507,827,828,831,833,835,838,840,843,845,847,850,852,855,857],{"class":509,"line":606},[507,829,830],{"class":525},"  (",[507,832,552],{"class":551},[507,834,568],{"class":525},[507,836,837],{"class":564}," void",[507,839,580],{"class":525},[507,841,842],{"class":564}," FatalError",[507,844,574],{"class":525},[507,846,588],{"class":525},[507,848,849],{"class":591},"not-authorized",[507,851,588],{"class":525},[507,853,854],{"class":525},">",[507,856,600],{"class":517},[507,858,603],{"class":525},[507,860,861,863,865,867,870,872,875,877,880,882,884,886,889,891,894,896,899,901,903,906,908],{"class":509,"line":647},[507,862,650],{"class":513},[507,864,548],{"class":634},[507,866,655],{"class":525},[507,868,869],{"class":521},"myApp",[507,871,532],{"class":525},[507,873,874],{"class":521},"auth",[507,876,532],{"class":525},[507,878,879],{"class":535},"getSessionUser",[507,881,635],{"class":634},[507,883,552],{"class":521},[507,885,532],{"class":525},[507,887,888],{"class":521},"request",[507,890,532],{"class":525},[507,892,893],{"class":521},"headers",[507,895,532],{"class":525},[507,897,898],{"class":535},"get",[507,900,635],{"class":634},[507,902,588],{"class":525},[507,904,905],{"class":591},"cookie",[507,907,588],{"class":525},[507,909,910],{"class":634},")))\n",[507,912,913,915,917,919,921],{"class":509,"line":667},[507,914,670],{"class":513},[507,916,673],{"class":525},[507,918,842],{"class":535},[507,920,635],{"class":634},[507,922,664],{"class":525},[507,924,925,927,929,931,934,936],{"class":509,"line":682},[507,926,685],{"class":634},[507,928,561],{"class":525},[507,930,721],{"class":525},[507,932,933],{"class":591},"Not Authorized",[507,935,588],{"class":525},[507,937,710],{"class":525},[507,939,940,942,944,946,948,950],{"class":509,"line":713},[507,941,716],{"class":634},[507,943,561],{"class":525},[507,945,721],{"class":525},[507,947,849],{"class":591},[507,949,588],{"class":525},[507,951,710],{"class":525},[507,953,954,956,958],{"class":509,"line":730},[507,955,733],{"class":525},[507,957,641],{"class":634},[507,959,644],{"class":525},[507,961,962],{"class":509,"line":740},[507,963,759],{"class":525},[507,965,966,968],{"class":509,"line":746},[507,967,641],{"class":521},[507,969,644],{"class":525},[774,971,972,973,975,976,979,980,982,983,532],{},"The client sees a returned ",[409,974,786],{}," like any declared error: at the middleware's path and in its ",[409,977,978],{},"onError"," listeners, never in ",[409,981,474],{},". It is not told the route was skipped: a route that returns a value simply gives ",[409,984,985],{},"undefined",[478,987,989],{"id":988},"http-status-codes","HTTP Status Codes",[405,991,992,993,995,996,999,1000,1002],{},"A ",[409,994,786],{}," sets the response's HTTP status from its ",[409,997,998],{},"statusCode",", such as 401. Without one it answers 400, a declared application error, like the auth gate above. A thrown error without a ",[409,1001,998],{}," answers 422, something the server did not expect.",[478,1004,1006],{"id":1005},"identifying-error-types","Identifying Error Types",[405,1008,1009,1010,1013],{},"The client gets returned errors fully typed. Tell them apart by ",[409,1011,1012],{},"error.type",", never by the HTTP status code, which is only a transport detail in an RPC API.",[498,1015,1017],{"className":500,"code":1016,"language":502,"meta":503,"style":503},"import {isRpcError} from '@mionjs\u002Fcore';\nimport {initClient} from '@mionjs\u002Fclient';\nimport type {MyApi} from '.\u002Fauth-user.routes.ts';\n\nconst {routes} = initClient\u003CMyApi>({\n  baseURL: 'http:\u002F\u002Flocalhost:3000',\n});\n\nconst [user, error, response] = await routes.users.getById('USER-404').call();\nconst thrown = response['@thrownErrors'];\n\n\u002F\u002F error.type is the discriminator, never the HTTP status code\nif (error) {\n  switch (error.type) {\n    case 'user-not-found':\n      \u002F\u002F declared payloads survive narrowing: errorData is UserNotFoundData\n      console.log('missing user:', error.errorData?.requestedId);\n      break;\n    case 'validation-error':\n      console.log('type errors:', error.errorData?.typeErrors.length);\n      break;\n  }\n} else if (isRpcError(response.auth)) {\n  \u002F\u002F the middleware's declared error; its onError hook gets it strongly typed\n  console.log('auth failed:', response.auth.type);\n} else if (thrown) {\n  \u002F\u002F transport, platform or any undeclared error lands here\n  console.log('request failed:', thrown[0].type);\n} else {\n  console.log(user?.name); \u002F\u002F John\n}\n\n\u002F\u002F typeErrors() is the only method that can throw\ntry {\n  const errors = await routes.users.getById(null as any).typeErrors();\n  console.log(errors); \u002F\u002F [] (empty array if no errors)\n} catch (validationError: any) {\n  \u002F\u002F { type: 'validation-error', message: `Invalid params ...` }\n  console.log(validationError);\n}\n",[409,1018,1019,1044,1066,1091,1097,1124,1140,1148,1152,1213,1235,1239,1244,1255,1275,1290,1296,1334,1342,1356,1396,1403,1408,1433,1439,1474,1488,1494,1534,1543,1569,1575,1580,1586,1594,1638,1659,1680,1686,1703],{"__ignoreMap":503},[507,1020,1021,1024,1027,1030,1032,1035,1037,1040,1042],{"class":509,"line":510},[507,1022,1023],{"class":513},"import",[507,1025,1026],{"class":525}," {",[507,1028,1029],{"class":521},"isRpcError",[507,1031,701],{"class":525},[507,1033,1034],{"class":513}," from",[507,1036,721],{"class":525},[507,1038,1039],{"class":591},"@mionjs\u002Fcore",[507,1041,588],{"class":525},[507,1043,644],{"class":525},[507,1045,1046,1048,1050,1053,1055,1057,1059,1062,1064],{"class":509,"line":542},[507,1047,1023],{"class":513},[507,1049,1026],{"class":525},[507,1051,1052],{"class":521},"initClient",[507,1054,701],{"class":525},[507,1056,1034],{"class":513},[507,1058,721],{"class":525},[507,1060,1061],{"class":591},"@mionjs\u002Fclient",[507,1063,588],{"class":525},[507,1065,644],{"class":525},[507,1067,1068,1070,1073,1075,1078,1080,1082,1084,1087,1089],{"class":509,"line":606},[507,1069,1023],{"class":513},[507,1071,1072],{"class":513}," type",[507,1074,1026],{"class":525},[507,1076,1077],{"class":521},"MyApi",[507,1079,701],{"class":525},[507,1081,1034],{"class":513},[507,1083,721],{"class":525},[507,1085,1086],{"class":591},".\u002Fauth-user.routes.ts",[507,1088,588],{"class":525},[507,1090,644],{"class":525},[507,1092,1093],{"class":509,"line":647},[507,1094,1096],{"emptyLinePlaceholder":1095},true,"\n",[507,1098,1099,1102,1104,1107,1109,1111,1114,1116,1118,1120,1122],{"class":509,"line":667},[507,1100,1101],{"class":517},"const",[507,1103,1026],{"class":525},[507,1105,1106],{"class":521},"routes",[507,1108,701],{"class":525},[507,1110,615],{"class":525},[507,1112,1113],{"class":535}," initClient",[507,1115,574],{"class":525},[507,1117,1077],{"class":564},[507,1119,854],{"class":525},[507,1121,635],{"class":521},[507,1123,664],{"class":525},[507,1125,1126,1129,1131,1133,1136,1138],{"class":509,"line":682},[507,1127,1128],{"class":634},"  baseURL",[507,1130,561],{"class":525},[507,1132,721],{"class":525},[507,1134,1135],{"class":591},"http:\u002F\u002Flocalhost:3000",[507,1137,588],{"class":525},[507,1139,710],{"class":525},[507,1141,1142,1144,1146],{"class":509,"line":713},[507,1143,701],{"class":525},[507,1145,641],{"class":521},[507,1147,644],{"class":525},[507,1149,1150],{"class":509,"line":730},[507,1151,1096],{"emptyLinePlaceholder":1095},[507,1153,1154,1156,1159,1162,1164,1167,1169,1172,1175,1177,1179,1182,1184,1187,1189,1192,1194,1196,1199,1201,1203,1205,1208,1211],{"class":509,"line":740},[507,1155,1101],{"class":517},[507,1157,1158],{"class":525}," [",[507,1160,1161],{"class":521},"user",[507,1163,555],{"class":525},[507,1165,1166],{"class":521}," error",[507,1168,555],{"class":525},[507,1170,1171],{"class":521}," response",[507,1173,1174],{"class":525},"]",[507,1176,615],{"class":525},[507,1178,618],{"class":513},[507,1180,1181],{"class":521}," routes",[507,1183,532],{"class":525},[507,1185,1186],{"class":521},"users",[507,1188,532],{"class":525},[507,1190,1191],{"class":535},"getById",[507,1193,635],{"class":521},[507,1195,588],{"class":525},[507,1197,1198],{"class":591},"USER-404",[507,1200,588],{"class":525},[507,1202,641],{"class":521},[507,1204,532],{"class":525},[507,1206,1207],{"class":535},"call",[507,1209,1210],{"class":521},"()",[507,1212,644],{"class":525},[507,1214,1215,1217,1220,1222,1225,1227,1229,1231,1233],{"class":509,"line":746},[507,1216,1101],{"class":517},[507,1218,1219],{"class":521}," thrown ",[507,1221,526],{"class":525},[507,1223,1224],{"class":521}," response[",[507,1226,588],{"class":525},[507,1228,474],{"class":591},[507,1230,588],{"class":525},[507,1232,1174],{"class":521},[507,1234,644],{"class":525},[507,1236,1237],{"class":509,"line":756},[507,1238,1096],{"emptyLinePlaceholder":1095},[507,1240,1241],{"class":509,"line":762},[507,1242,1243],{"class":804},"\u002F\u002F error.type is the discriminator, never the HTTP status code\n",[507,1245,1247,1250,1253],{"class":509,"line":1246},13,[507,1248,1249],{"class":513},"if",[507,1251,1252],{"class":521}," (error) ",[507,1254,664],{"class":525},[507,1256,1258,1261,1263,1266,1268,1271,1273],{"class":509,"line":1257},14,[507,1259,1260],{"class":513},"  switch",[507,1262,548],{"class":634},[507,1264,1265],{"class":521},"error",[507,1267,532],{"class":525},[507,1269,1270],{"class":521},"type",[507,1272,661],{"class":634},[507,1274,664],{"class":525},[507,1276,1278,1281,1283,1285,1287],{"class":509,"line":1277},15,[507,1279,1280],{"class":513},"    case",[507,1282,721],{"class":525},[507,1284,495],{"class":591},[507,1286,588],{"class":525},[507,1288,1289],{"class":525},":\n",[507,1291,1293],{"class":509,"line":1292},16,[507,1294,1295],{"class":804},"      \u002F\u002F declared payloads survive narrowing: errorData is UserNotFoundData\n",[507,1297,1299,1302,1304,1307,1309,1311,1314,1316,1318,1320,1322,1324,1327,1330,1332],{"class":509,"line":1298},17,[507,1300,1301],{"class":521},"      console",[507,1303,532],{"class":525},[507,1305,1306],{"class":535},"log",[507,1308,635],{"class":634},[507,1310,588],{"class":525},[507,1312,1313],{"class":591},"missing user:",[507,1315,588],{"class":525},[507,1317,555],{"class":525},[507,1319,1166],{"class":521},[507,1321,532],{"class":525},[507,1323,491],{"class":521},[507,1325,1326],{"class":525},"?.",[507,1328,1329],{"class":521},"requestedId",[507,1331,641],{"class":634},[507,1333,644],{"class":525},[507,1335,1337,1340],{"class":509,"line":1336},18,[507,1338,1339],{"class":513},"      break",[507,1341,644],{"class":525},[507,1343,1345,1347,1349,1352,1354],{"class":509,"line":1344},19,[507,1346,1280],{"class":513},[507,1348,721],{"class":525},[507,1350,1351],{"class":591},"validation-error",[507,1353,588],{"class":525},[507,1355,1289],{"class":525},[507,1357,1359,1361,1363,1365,1367,1369,1372,1374,1376,1378,1380,1382,1384,1387,1389,1392,1394],{"class":509,"line":1358},20,[507,1360,1301],{"class":521},[507,1362,532],{"class":525},[507,1364,1306],{"class":535},[507,1366,635],{"class":634},[507,1368,588],{"class":525},[507,1370,1371],{"class":591},"type errors:",[507,1373,588],{"class":525},[507,1375,555],{"class":525},[507,1377,1166],{"class":521},[507,1379,532],{"class":525},[507,1381,491],{"class":521},[507,1383,1326],{"class":525},[507,1385,1386],{"class":521},"typeErrors",[507,1388,532],{"class":525},[507,1390,1391],{"class":521},"length",[507,1393,641],{"class":634},[507,1395,644],{"class":525},[507,1397,1399,1401],{"class":509,"line":1398},21,[507,1400,1339],{"class":513},[507,1402,644],{"class":525},[507,1404,1406],{"class":509,"line":1405},22,[507,1407,759],{"class":525},[507,1409,1411,1413,1416,1419,1421,1423,1426,1428,1431],{"class":509,"line":1410},23,[507,1412,701],{"class":525},[507,1414,1415],{"class":513}," else",[507,1417,1418],{"class":513}," if",[507,1420,548],{"class":521},[507,1422,1029],{"class":535},[507,1424,1425],{"class":521},"(response",[507,1427,532],{"class":525},[507,1429,1430],{"class":521},"auth)) ",[507,1432,664],{"class":525},[507,1434,1436],{"class":509,"line":1435},24,[507,1437,1438],{"class":804},"  \u002F\u002F the middleware's declared error; its onError hook gets it strongly typed\n",[507,1440,1442,1445,1447,1449,1451,1453,1456,1458,1460,1462,1464,1466,1468,1470,1472],{"class":509,"line":1441},25,[507,1443,1444],{"class":521},"  console",[507,1446,532],{"class":525},[507,1448,1306],{"class":535},[507,1450,635],{"class":634},[507,1452,588],{"class":525},[507,1454,1455],{"class":591},"auth failed:",[507,1457,588],{"class":525},[507,1459,555],{"class":525},[507,1461,1171],{"class":521},[507,1463,532],{"class":525},[507,1465,874],{"class":521},[507,1467,532],{"class":525},[507,1469,1270],{"class":521},[507,1471,641],{"class":634},[507,1473,644],{"class":525},[507,1475,1477,1479,1481,1483,1486],{"class":509,"line":1476},26,[507,1478,701],{"class":525},[507,1480,1415],{"class":513},[507,1482,1418],{"class":513},[507,1484,1485],{"class":521}," (thrown) ",[507,1487,664],{"class":525},[507,1489,1491],{"class":509,"line":1490},27,[507,1492,1493],{"class":804},"  \u002F\u002F transport, platform or any undeclared error lands here\n",[507,1495,1497,1499,1501,1503,1505,1507,1510,1512,1514,1517,1520,1524,1526,1528,1530,1532],{"class":509,"line":1496},28,[507,1498,1444],{"class":521},[507,1500,532],{"class":525},[507,1502,1306],{"class":535},[507,1504,635],{"class":634},[507,1506,588],{"class":525},[507,1508,1509],{"class":591},"request failed:",[507,1511,588],{"class":525},[507,1513,555],{"class":525},[507,1515,1516],{"class":521}," thrown",[507,1518,1519],{"class":634},"[",[507,1521,1523],{"class":1522},"sbssI","0",[507,1525,1174],{"class":634},[507,1527,532],{"class":525},[507,1529,1270],{"class":521},[507,1531,641],{"class":634},[507,1533,644],{"class":525},[507,1535,1537,1539,1541],{"class":509,"line":1536},29,[507,1538,701],{"class":525},[507,1540,1415],{"class":513},[507,1542,603],{"class":525},[507,1544,1546,1548,1550,1552,1554,1556,1558,1561,1563,1566],{"class":509,"line":1545},30,[507,1547,1444],{"class":521},[507,1549,532],{"class":525},[507,1551,1306],{"class":535},[507,1553,635],{"class":634},[507,1555,1161],{"class":521},[507,1557,1326],{"class":525},[507,1559,1560],{"class":521},"name",[507,1562,641],{"class":634},[507,1564,1565],{"class":525},";",[507,1567,1568],{"class":804}," \u002F\u002F John\n",[507,1570,1572],{"class":509,"line":1571},31,[507,1573,1574],{"class":525},"}\n",[507,1576,1578],{"class":509,"line":1577},32,[507,1579,1096],{"emptyLinePlaceholder":1095},[507,1581,1583],{"class":509,"line":1582},33,[507,1584,1585],{"class":804},"\u002F\u002F typeErrors() is the only method that can throw\n",[507,1587,1589,1592],{"class":509,"line":1588},34,[507,1590,1591],{"class":513},"try",[507,1593,603],{"class":525},[507,1595,1597,1600,1603,1605,1607,1609,1611,1613,1615,1617,1619,1622,1625,1628,1630,1632,1634,1636],{"class":509,"line":1596},35,[507,1598,1599],{"class":517},"  const",[507,1601,1602],{"class":521}," errors",[507,1604,615],{"class":525},[507,1606,618],{"class":513},[507,1608,1181],{"class":521},[507,1610,532],{"class":525},[507,1612,1186],{"class":521},[507,1614,532],{"class":525},[507,1616,1191],{"class":535},[507,1618,635],{"class":634},[507,1620,1621],{"class":525},"null",[507,1623,1624],{"class":513}," as",[507,1626,1627],{"class":564}," any",[507,1629,641],{"class":634},[507,1631,532],{"class":525},[507,1633,1386],{"class":535},[507,1635,1210],{"class":634},[507,1637,644],{"class":525},[507,1639,1641,1643,1645,1647,1649,1652,1654,1656],{"class":509,"line":1640},36,[507,1642,1444],{"class":521},[507,1644,532],{"class":525},[507,1646,1306],{"class":535},[507,1648,635],{"class":634},[507,1650,1651],{"class":521},"errors",[507,1653,641],{"class":634},[507,1655,1565],{"class":525},[507,1657,1658],{"class":804}," \u002F\u002F [] (empty array if no errors)\n",[507,1660,1662,1664,1667,1669,1672,1674,1676,1678],{"class":509,"line":1661},37,[507,1663,701],{"class":525},[507,1665,1666],{"class":513}," catch",[507,1668,548],{"class":525},[507,1670,1671],{"class":551},"validationError",[507,1673,561],{"class":525},[507,1675,1627],{"class":564},[507,1677,641],{"class":525},[507,1679,603],{"class":525},[507,1681,1683],{"class":509,"line":1682},38,[507,1684,1685],{"class":804},"  \u002F\u002F { type: 'validation-error', message: `Invalid params ...` }\n",[507,1687,1689,1691,1693,1695,1697,1699,1701],{"class":509,"line":1688},39,[507,1690,1444],{"class":521},[507,1692,532],{"class":525},[507,1694,1306],{"class":535},[507,1696,635],{"class":634},[507,1698,1671],{"class":521},[507,1700,641],{"class":634},[507,1702,644],{"class":525},[507,1704,1706],{"class":509,"line":1705},40,[507,1707,1574],{"class":525},[478,1709,1711],{"id":1710},"throwing-errors-discouraged","Throwing Errors (Discouraged)",[405,1713,1714,1715,1717,1718,1721,1722,532],{},"Throw only for truly unexpected situations, like bugs or infrastructure failures. A thrown error ends the request like a ",[409,1716,786],{},", but it is not in the function signature, so the client gets only its ",[409,1719,1720],{},"publicMessage",", in ",[409,1723,474],{},[498,1725,1727],{"className":500,"code":1726,"language":502,"meta":503,"style":503},"export const updatePet = mion.route(async (ctx, pet: Pet): Promise\u003CPet> => {\n  try {\n    return await myApp.db.updatePet(pet);\n  } catch (dbError) {\n    \u002F\u002F a logger still reads the full error on ctx.request.thrownErrors and ctx.response.fatalError\n    throw new RpcError({\n      publicMessage: `Cant update the pet.`,\n      message: (dbError as Error).message,\n      originalError: dbError as Error,\n      type: 'db-error',\n    });\n  }\n}) satisfies Route;\n\nexport const alwaysError = mion.route((): void => {\n  throw new Error('the client gets a 422 unknown-error, never this message');\n}) satisfies Route;\n",[409,1728,1729,1778,1785,1810,1826,1831,1844,1860,1885,1901,1917,1926,1930,1942,1946,1974,1996],{"__ignoreMap":503},[507,1730,1731,1733,1735,1738,1740,1742,1744,1746,1748,1751,1753,1755,1757,1759,1761,1764,1766,1768,1770,1772,1774,1776],{"class":509,"line":510},[507,1732,514],{"class":513},[507,1734,518],{"class":517},[507,1736,1737],{"class":521}," updatePet ",[507,1739,526],{"class":525},[507,1741,529],{"class":521},[507,1743,532],{"class":525},[507,1745,536],{"class":535},[507,1747,635],{"class":521},[507,1749,1750],{"class":517},"async",[507,1752,548],{"class":525},[507,1754,552],{"class":551},[507,1756,555],{"class":525},[507,1758,612],{"class":551},[507,1760,561],{"class":525},[507,1762,1763],{"class":564}," Pet",[507,1765,568],{"class":525},[507,1767,571],{"class":564},[507,1769,574],{"class":525},[507,1771,577],{"class":564},[507,1773,854],{"class":525},[507,1775,600],{"class":517},[507,1777,603],{"class":525},[507,1779,1780,1783],{"class":509,"line":542},[507,1781,1782],{"class":513},"  try",[507,1784,603],{"class":525},[507,1786,1787,1789,1791,1793,1795,1797,1799,1802,1804,1806,1808],{"class":509,"line":606},[507,1788,749],{"class":513},[507,1790,618],{"class":513},[507,1792,621],{"class":521},[507,1794,532],{"class":525},[507,1796,626],{"class":521},[507,1798,532],{"class":525},[507,1800,1801],{"class":535},"updatePet",[507,1803,635],{"class":634},[507,1805,658],{"class":521},[507,1807,641],{"class":634},[507,1809,644],{"class":525},[507,1811,1812,1815,1817,1819,1822,1824],{"class":509,"line":647},[507,1813,1814],{"class":525},"  }",[507,1816,1666],{"class":513},[507,1818,548],{"class":634},[507,1820,1821],{"class":521},"dbError",[507,1823,661],{"class":634},[507,1825,664],{"class":525},[507,1827,1828],{"class":509,"line":667},[507,1829,1830],{"class":804},"    \u002F\u002F a logger still reads the full error on ctx.request.thrownErrors and ctx.response.fatalError\n",[507,1832,1833,1836,1838,1840,1842],{"class":509,"line":682},[507,1834,1835],{"class":513},"    throw",[507,1837,673],{"class":525},[507,1839,583],{"class":535},[507,1841,635],{"class":634},[507,1843,664],{"class":525},[507,1845,1846,1849,1851,1853,1856,1858],{"class":509,"line":713},[507,1847,1848],{"class":634},"      publicMessage",[507,1850,561],{"class":525},[507,1852,690],{"class":525},[507,1854,1855],{"class":591},"Cant update the pet.",[507,1857,707],{"class":525},[507,1859,710],{"class":525},[507,1861,1862,1865,1867,1869,1871,1873,1876,1878,1880,1883],{"class":509,"line":730},[507,1863,1864],{"class":634},"      message",[507,1866,561],{"class":525},[507,1868,548],{"class":634},[507,1870,1821],{"class":521},[507,1872,1624],{"class":513},[507,1874,1875],{"class":564}," Error",[507,1877,641],{"class":634},[507,1879,532],{"class":525},[507,1881,1882],{"class":521},"message",[507,1884,710],{"class":525},[507,1886,1887,1890,1892,1895,1897,1899],{"class":509,"line":740},[507,1888,1889],{"class":634},"      originalError",[507,1891,561],{"class":525},[507,1893,1894],{"class":521}," dbError",[507,1896,1624],{"class":513},[507,1898,1875],{"class":564},[507,1900,710],{"class":525},[507,1902,1903,1906,1908,1910,1913,1915],{"class":509,"line":746},[507,1904,1905],{"class":634},"      type",[507,1907,561],{"class":525},[507,1909,721],{"class":525},[507,1911,1912],{"class":591},"db-error",[507,1914,588],{"class":525},[507,1916,710],{"class":525},[507,1918,1919,1922,1924],{"class":509,"line":756},[507,1920,1921],{"class":525},"    }",[507,1923,641],{"class":634},[507,1925,644],{"class":525},[507,1927,1928],{"class":509,"line":762},[507,1929,759],{"class":525},[507,1931,1932,1934,1936,1938,1940],{"class":509,"line":1246},[507,1933,701],{"class":525},[507,1935,661],{"class":521},[507,1937,767],{"class":513},[507,1939,770],{"class":564},[507,1941,644],{"class":525},[507,1943,1944],{"class":509,"line":1257},[507,1945,1096],{"emptyLinePlaceholder":1095},[507,1947,1948,1950,1952,1955,1957,1959,1961,1963,1965,1968,1970,1972],{"class":509,"line":1277},[507,1949,514],{"class":513},[507,1951,518],{"class":517},[507,1953,1954],{"class":521}," alwaysError ",[507,1956,526],{"class":525},[507,1958,529],{"class":521},[507,1960,532],{"class":525},[507,1962,536],{"class":535},[507,1964,635],{"class":521},[507,1966,1967],{"class":525},"():",[507,1969,837],{"class":564},[507,1971,600],{"class":517},[507,1973,603],{"class":525},[507,1975,1976,1979,1981,1983,1985,1987,1990,1992,1994],{"class":509,"line":1292},[507,1977,1978],{"class":513},"  throw",[507,1980,673],{"class":525},[507,1982,1875],{"class":535},[507,1984,635],{"class":634},[507,1986,588],{"class":525},[507,1988,1989],{"class":591},"the client gets a 422 unknown-error, never this message",[507,1991,588],{"class":525},[507,1993,641],{"class":634},[507,1995,644],{"class":525},[507,1997,1998,2000,2002,2004,2006],{"class":509,"line":1298},[507,1999,701],{"class":525},[507,2001,661],{"class":521},[507,2003,767],{"class":513},[507,2005,770],{"class":564},[507,2007,644],{"class":525},[405,2009,2010,2011,2013],{},"The router itself throws for what nobody declared: a missing route, an unreadable body, a payload over the limit. The exception is ",[409,2012,1351],{},": it is thrown on the server but is part of every route's contract, so the client still gets it typed.",[2015,2016,2017,2018,2022,2023,2025,2026,2029,2030,2033],"note",{},"The ",[2019,2020,2021],"a",{"href":144},"linter"," reports a ",[409,2024,467],{}," inside a handler as ",[409,2027,2028],{},"rpc-handler-throws",". To keep a throw, add ",[409,2031,2032],{},"\u002F\u002F @mion-expect-error rpc-handler-throws"," above it, and a comment saying why.",[478,2035,2037],{"id":2036},"error-response-format","Error Response Format",[2039,2040,2041,2051],"ul",{},[2042,2043,2044,2047,2048,2050],"li",{},[485,2045,2046],{},"Returned errors"," (strongly typed), a ",[409,2049,786],{}," included, appear under the route or middleware id with their type information.",[2042,2052,2053,2056,2057,2059],{},[485,2054,2055],{},"Thrown errors"," (untyped) go in the ",[409,2058,474],{}," field.",[498,2061,2065],{"className":2062,"code":2063,"language":2064,"meta":503,"style":503},"language-json shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","{\n    \"getUser\": [0, {\n        \"type\": \"user-not-found\",\n        \"publicMessage\": \"User not found\",\n        \"errorData\": {\"userId\": \"123\"}\n    }],\n    \"@thrownErrors\": {\n        \"someMiddleware\": {\n            \"type\": \"unknown-error\",\n            \"publicMessage\": \"Unknown error in handler \\\"someMiddleware\\\" of route ExecutionChain.\",\n            \"statusCode\": 422\n        }\n    }\n}\n","json",[409,2066,2067,2071,2092,2112,2131,2161,2166,2178,2191,2211,2240,2253,2258,2262],{"__ignoreMap":503},[507,2068,2069],{"class":509,"line":510},[507,2070,664],{"class":525},[507,2072,2073,2076,2079,2082,2084,2086,2088,2090],{"class":509,"line":542},[507,2074,2075],{"class":525},"    \"",[507,2077,2078],{"class":517},"getUser",[507,2080,2081],{"class":525},"\"",[507,2083,561],{"class":525},[507,2085,1158],{"class":525},[507,2087,1523],{"class":1522},[507,2089,555],{"class":525},[507,2091,603],{"class":525},[507,2093,2094,2097,2099,2101,2103,2106,2108,2110],{"class":509,"line":606},[507,2095,2096],{"class":525},"        \"",[507,2098,1270],{"class":564},[507,2100,2081],{"class":525},[507,2102,561],{"class":525},[507,2104,2105],{"class":525}," \"",[507,2107,495],{"class":591},[507,2109,2081],{"class":525},[507,2111,710],{"class":525},[507,2113,2114,2116,2118,2120,2122,2124,2127,2129],{"class":509,"line":647},[507,2115,2096],{"class":525},[507,2117,1720],{"class":564},[507,2119,2081],{"class":525},[507,2121,561],{"class":525},[507,2123,2105],{"class":525},[507,2125,2126],{"class":591},"User not found",[507,2128,2081],{"class":525},[507,2130,710],{"class":525},[507,2132,2133,2135,2137,2139,2141,2143,2145,2148,2150,2152,2154,2157,2159],{"class":509,"line":667},[507,2134,2096],{"class":525},[507,2136,491],{"class":564},[507,2138,2081],{"class":525},[507,2140,561],{"class":525},[507,2142,1026],{"class":525},[507,2144,2081],{"class":525},[507,2146,2147],{"class":1522},"userId",[507,2149,2081],{"class":525},[507,2151,561],{"class":525},[507,2153,2105],{"class":525},[507,2155,2156],{"class":591},"123",[507,2158,2081],{"class":525},[507,2160,1574],{"class":525},[507,2162,2163],{"class":509,"line":682},[507,2164,2165],{"class":525},"    }],\n",[507,2167,2168,2170,2172,2174,2176],{"class":509,"line":713},[507,2169,2075],{"class":525},[507,2171,474],{"class":517},[507,2173,2081],{"class":525},[507,2175,561],{"class":525},[507,2177,603],{"class":525},[507,2179,2180,2182,2185,2187,2189],{"class":509,"line":730},[507,2181,2096],{"class":525},[507,2183,2184],{"class":564},"someMiddleware",[507,2186,2081],{"class":525},[507,2188,561],{"class":525},[507,2190,603],{"class":525},[507,2192,2193,2196,2198,2200,2202,2204,2207,2209],{"class":509,"line":740},[507,2194,2195],{"class":525},"            \"",[507,2197,1270],{"class":1522},[507,2199,2081],{"class":525},[507,2201,561],{"class":525},[507,2203,2105],{"class":525},[507,2205,2206],{"class":591},"unknown-error",[507,2208,2081],{"class":525},[507,2210,710],{"class":525},[507,2212,2213,2215,2217,2219,2221,2223,2226,2229,2231,2233,2236,2238],{"class":509,"line":746},[507,2214,2195],{"class":525},[507,2216,1720],{"class":1522},[507,2218,2081],{"class":525},[507,2220,561],{"class":525},[507,2222,2105],{"class":525},[507,2224,2225],{"class":591},"Unknown error in handler ",[507,2227,2228],{"class":521},"\\\"",[507,2230,2184],{"class":591},[507,2232,2228],{"class":521},[507,2234,2235],{"class":591}," of route ExecutionChain.",[507,2237,2081],{"class":525},[507,2239,710],{"class":525},[507,2241,2242,2244,2246,2248,2250],{"class":509,"line":756},[507,2243,2195],{"class":525},[507,2245,998],{"class":1522},[507,2247,2081],{"class":525},[507,2249,561],{"class":525},[507,2251,2252],{"class":1522}," 422\n",[507,2254,2255],{"class":509,"line":762},[507,2256,2257],{"class":525},"        }\n",[507,2259,2260],{"class":509,"line":1246},[507,2261,743],{"class":525},[507,2263,2264],{"class":509,"line":1257},[507,2265,1574],{"class":525},[405,2267,2268,2270,2271,2274,2275,2278],{},[409,2269,2078],{}," returns ",[409,2272,2273],{},"User | RpcError",", so its value is sent as an ",[409,2276,2277],{},"[index, value]"," pair.",[2015,2280,2281,2282,2284],{},"The mion client handles this for you: read the error from the result. Only public fields are sent: the internal ",[409,2283,1882],{},", the fatal flag and the stack stay on the server.",[478,2286,2288],{"id":2287},"always-run-middleware","Always Run Middleware",[405,2290,2291,2292,2295,2296,532],{},"A middleware with ",[409,2293,2294],{},"alwaysRun: true"," runs even after an error ended the request, see ",[2019,2297,2299],{"href":2298},"\u002Frpc\u002Fserver\u002Fmiddleware#always-run","Always Run",[2301,2302,2303],"style",{},"html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}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);}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}","Return errors so the client gets them typed, and end the request when it must stop.","md",null,{"toc":24},{"title":48,"description":2304},"lXRRhlXPGyDevmXNwXcVBsCCvN-WjhdkmGRMy8KIdSQ",1793324369595]