@stacksjs/error-handling 0.74.27 → 0.74.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var {require}=import.meta;const DOCS_BASE="https://stacksjs.org/docs/errors";export const HTTP_ERRORS={400:{status:400,title:"Bad Request",message:"The request was malformed or invalid.",docLink:`${DOCS_BASE}/400`,commonCauses:["JSON body is missing or has a syntax error","A required field is absent from the payload","Content-Type header does not match the body format"],suggestion:"Inspect the request body and Content-Type - most 400s come from malformed JSON or a missing required field."},401:{status:401,title:"Unauthorized",message:"Authentication is required to access this resource.",docLink:`${DOCS_BASE}/401`,commonCauses:["No Authorization header was sent","The bearer token expired","The session cookie was cleared"],suggestion:"Confirm a valid `Authorization: Bearer <token>` header is sent and the token has not expired."},403:{status:403,title:"Forbidden",message:"You do not have permission to access this resource.",docLink:`${DOCS_BASE}/403`,commonCauses:["The authenticated user lacks the required ability or role","A Gate or policy denied access (see app/Gates.ts)","The token was issued without the needed ability"],suggestion:"Check Gates / policies and the abilities encoded in the access token."},404:{status:404,title:"Not Found",message:"The requested resource could not be found.",docLink:`${DOCS_BASE}/404`,commonCauses:["The route is not registered in app/Routes.ts","A typo in the URL path","A model lookup returned no row (ModelNotFoundError)"],suggestion:"Run `buddy route:list` to see registered routes, or verify the model exists with the given id."},405:{status:405,title:"Method Not Allowed",message:"The request method is not supported for this resource.",docLink:`${DOCS_BASE}/405`,commonCauses:["The route is registered for a different HTTP method","A form posted GET when the route expects POST"],suggestion:"Confirm the HTTP method in `app/Routes.ts` matches what the client sent."},408:{status:408,title:"Request Timeout",message:"The request took too long to complete.",docLink:`${DOCS_BASE}/408`,commonCauses:["A long-running query or external API call exceeded the timeout","The client uploaded a slow body that stalled"],suggestion:"Move slow work into a queued job, or raise the route timeout if the work is genuinely long."},409:{status:409,title:"Conflict",message:"The request conflicts with the current state of the resource.",docLink:`${DOCS_BASE}/409`,commonCauses:["A unique-constraint violation (duplicate email, slug, etc.)","Optimistic locking detected a stale write"],suggestion:"Re-fetch the resource and retry, or surface the conflict to the user."},410:{status:410,title:"Gone",message:"The requested resource is no longer available.",docLink:`${DOCS_BASE}/410`,commonCauses:["The resource was permanently deleted","A signed URL expired"],suggestion:"Issue a fresh signed URL or fall back to the canonical resource."},422:{status:422,title:"Unprocessable Entity",message:"The request was well-formed but could not be processed.",docLink:`${DOCS_BASE}/422`,commonCauses:["Validation rules from the action / model rejected the payload","A field value is outside the allowed range or shape"],suggestion:"Inspect `errors` in the response body - each key maps to a failing field."},429:{status:429,title:"Too Many Requests",message:"You have exceeded the rate limit.",docLink:`${DOCS_BASE}/429`,commonCauses:["Rate-limit middleware tripped on this IP / token","A retry loop is hammering the endpoint"],suggestion:"Honor the `Retry-After` response header and back off before retrying."},500:{status:500,title:"Internal Server Error",message:"An unexpected error occurred on the server.",docLink:`${DOCS_BASE}/500`,commonCauses:["An unhandled exception in an action or middleware","A failing database connection or migration","A misconfigured environment variable"],suggestion:"Check server logs for the original stack trace - the error page above shows the throw site in dev."},502:{status:502,title:"Bad Gateway",message:"The server received an invalid response from an upstream server.",docLink:`${DOCS_BASE}/502`,commonCauses:["An upstream HTTP API returned a malformed response","A reverse proxy could not reach the origin"],suggestion:"Verify the upstream service is healthy and returning the expected content type."},503:{status:503,title:"Service Unavailable",message:"The service is temporarily unavailable.",docLink:`${DOCS_BASE}/503`,commonCauses:["Maintenance mode is enabled","A health check is failing","A dependency (db, redis, queue) is down"],suggestion:"Run `buddy doctor` and check dependent services."},504:{status:504,title:"Gateway Timeout",message:"The upstream server did not respond in time.",docLink:`${DOCS_BASE}/504`,commonCauses:["An upstream HTTP call exceeded its deadline","A long-running database query timed out"],suggestion:"Move the work to a queued job or raise the upstream timeout if the latency is expected."}};import{buildErrorMarkdown,escapeHtml,renderExceptionTrace,wrapErrorPage}from"./error-page-template";import{errorIllustration}from"./error-illustrations";import{ERROR_PAGE_CSS}from"./error-page-styles";export{ERROR_PAGE_CSS};const FRAMEWORK_FRAME_FRAGMENTS=["/storage/framework/core/","/node_modules/@stacksjs/","node:internal/","bun:wrap"];export function isFrameworkFrame(file){if(!file)return!1;return FRAMEWORK_FRAME_FRAGMENTS.some((f)=>file.includes(f))}function parseStackTrace(stack,basePaths,options={}){if(!stack)return[];const lines=stack.split(`
1
+ var {require}=import.meta;const DOCS_BASE="https://stacksjs.com/docs/errors";export const HTTP_ERRORS={400:{status:400,title:"Bad Request",message:"The request was malformed or invalid.",docLink:`${DOCS_BASE}/400`,commonCauses:["JSON body is missing or has a syntax error","A required field is absent from the payload","Content-Type header does not match the body format"],suggestion:"Inspect the request body and Content-Type - most 400s come from malformed JSON or a missing required field."},401:{status:401,title:"Unauthorized",message:"Authentication is required to access this resource.",docLink:`${DOCS_BASE}/401`,commonCauses:["No Authorization header was sent","The bearer token expired","The session cookie was cleared"],suggestion:"Confirm a valid `Authorization: Bearer <token>` header is sent and the token has not expired."},403:{status:403,title:"Forbidden",message:"You do not have permission to access this resource.",docLink:`${DOCS_BASE}/403`,commonCauses:["The authenticated user lacks the required ability or role","A Gate or policy denied access (see app/Gates.ts)","The token was issued without the needed ability"],suggestion:"Check Gates / policies and the abilities encoded in the access token."},404:{status:404,title:"Not Found",message:"The requested resource could not be found.",docLink:`${DOCS_BASE}/404`,commonCauses:["The route is not registered in app/Routes.ts","A typo in the URL path","A model lookup returned no row (ModelNotFoundError)"],suggestion:"Run `buddy route:list` to see registered routes, or verify the model exists with the given id."},405:{status:405,title:"Method Not Allowed",message:"The request method is not supported for this resource.",docLink:`${DOCS_BASE}/405`,commonCauses:["The route is registered for a different HTTP method","A form posted GET when the route expects POST"],suggestion:"Confirm the HTTP method in `app/Routes.ts` matches what the client sent."},408:{status:408,title:"Request Timeout",message:"The request took too long to complete.",docLink:`${DOCS_BASE}/408`,commonCauses:["A long-running query or external API call exceeded the timeout","The client uploaded a slow body that stalled"],suggestion:"Move slow work into a queued job, or raise the route timeout if the work is genuinely long."},409:{status:409,title:"Conflict",message:"The request conflicts with the current state of the resource.",docLink:`${DOCS_BASE}/409`,commonCauses:["A unique-constraint violation (duplicate email, slug, etc.)","Optimistic locking detected a stale write"],suggestion:"Re-fetch the resource and retry, or surface the conflict to the user."},410:{status:410,title:"Gone",message:"The requested resource is no longer available.",docLink:`${DOCS_BASE}/410`,commonCauses:["The resource was permanently deleted","A signed URL expired"],suggestion:"Issue a fresh signed URL or fall back to the canonical resource."},422:{status:422,title:"Unprocessable Entity",message:"The request was well-formed but could not be processed.",docLink:`${DOCS_BASE}/422`,commonCauses:["Validation rules from the action / model rejected the payload","A field value is outside the allowed range or shape"],suggestion:"Inspect `errors` in the response body - each key maps to a failing field."},429:{status:429,title:"Too Many Requests",message:"You have exceeded the rate limit.",docLink:`${DOCS_BASE}/429`,commonCauses:["Rate-limit middleware tripped on this IP / token","A retry loop is hammering the endpoint"],suggestion:"Honor the `Retry-After` response header and back off before retrying."},500:{status:500,title:"Internal Server Error",message:"An unexpected error occurred on the server.",docLink:`${DOCS_BASE}/500`,commonCauses:["An unhandled exception in an action or middleware","A failing database connection or migration","A misconfigured environment variable"],suggestion:"Check server logs for the original stack trace - the error page above shows the throw site in dev."},502:{status:502,title:"Bad Gateway",message:"The server received an invalid response from an upstream server.",docLink:`${DOCS_BASE}/502`,commonCauses:["An upstream HTTP API returned a malformed response","A reverse proxy could not reach the origin"],suggestion:"Verify the upstream service is healthy and returning the expected content type."},503:{status:503,title:"Service Unavailable",message:"The service is temporarily unavailable.",docLink:`${DOCS_BASE}/503`,commonCauses:["Maintenance mode is enabled","A health check is failing","A dependency (db, redis, queue) is down"],suggestion:"Run `buddy doctor` and check dependent services."},504:{status:504,title:"Gateway Timeout",message:"The upstream server did not respond in time.",docLink:`${DOCS_BASE}/504`,commonCauses:["An upstream HTTP call exceeded its deadline","A long-running database query timed out"],suggestion:"Move the work to a queued job or raise the upstream timeout if the latency is expected."}};import{buildErrorMarkdown,escapeHtml,renderExceptionTrace,wrapErrorPage}from"./error-page-template";import{errorIllustration}from"./error-illustrations";import{ERROR_PAGE_CSS}from"./error-page-styles";export{ERROR_PAGE_CSS};const FRAMEWORK_FRAME_FRAGMENTS=["/storage/framework/core/","/node_modules/@stacksjs/","node:internal/","bun:wrap"];export function isFrameworkFrame(file){if(!file)return!1;return FRAMEWORK_FRAME_FRAGMENTS.some((f)=>file.includes(f))}function parseStackTrace(stack,basePaths,options={}){if(!stack)return[];const lines=stack.split(`
2
2
  `).slice(1),frames=[],includeAll=options.includeFrameworkFrames===!0;for(const line of lines){const match=line.match(/^\s*at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);if(match){let file=match[2];if(file===void 0)continue;const original=file,isFramework=isFrameworkFrame(original);if(basePaths){for(const basePath of basePaths)if(file.startsWith(basePath)){file=file.slice(basePath.length+1);break}}if(!includeAll&&isFramework)continue;frames.push({function:match[1]||"<anonymous>",file,absoluteFile:original,isFramework,line:parseInt(match[3]??"0",10),column:parseInt(match[4]??"0",10)})}}if(!includeAll&&frames.length===0)return parseStackTrace(stack,basePaths,{includeFrameworkFrames:!0});return frames}function loadCustomErrorPage(status,title,message){let resourcesPath;try{const mod=require("@stacksjs/path");resourcesPath=mod.resourcesPath??mod.path?.resourcesPath}catch{}if(!resourcesPath)return null;const fs=require("node:fs"),candidates=[resourcesPath(`views/errors/${status}.html`),resourcesPath("views/errors/error.html")];for(const filePath of candidates)try{if(!fs.existsSync(filePath))continue;return fs.readFileSync(filePath,"utf-8").replace(/\{\{\s*status\s*\}\}/g,escapeHtml(String(status))).replace(/\{\{\s*title\s*\}\}/g,escapeHtml(title)).replace(/\{\{\s*message\s*\}\}/g,escapeHtml(message))}catch{}return null}export function renderProductionErrorPage(status){const httpError=HTTP_ERRORS[status]||{status,title:"Error",message:"An unexpected error occurred."},custom=loadCustomErrorPage(httpError.status,httpError.title,httpError.message);if(custom!==null)return custom;return`<!DOCTYPE html>
3
3
  <html lang="en">
4
4
  <head>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/error-handling",
3
3
  "type": "module",
4
- "version": "0.74.27",
4
+ "version": "0.74.29",
5
5
  "description": "Type safe error handling.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -57,16 +57,16 @@
57
57
  "prepublishOnly": "bun run build"
58
58
  },
59
59
  "dependencies": {
60
- "@stacksjs/path": "0.74.27",
60
+ "@stacksjs/path": "0.74.29",
61
61
  "@stacksjs/stx": "^0.2.274",
62
- "@stacksjs/types": "0.74.27",
62
+ "@stacksjs/types": "0.74.29",
63
63
  "ts-error-handling": "^0.1.1",
64
64
  "ts-syntax-highlighter": "^0.2.1"
65
65
  },
66
66
  "devDependencies": {
67
- "@stacksjs/cli": "0.74.27",
68
- "@stacksjs/config": "0.74.27",
69
- "@stacksjs/validation": "0.74.27",
67
+ "@stacksjs/cli": "0.74.29",
68
+ "@stacksjs/config": "0.74.29",
69
+ "@stacksjs/validation": "0.74.29",
70
70
  "better-dx": "^0.2.24"
71
71
  },
72
72
  "sideEffects": false