@stacksjs/error-handling 0.75.255 → 0.75.257
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.
- package/dist/http.js +1 -1
- package/package.json +7 -7
package/dist/http.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createErrorHandler,renderProductionErrorPage}from"./error-page";import{HttpError}from"./http-error";export{HttpError}from"./http-error";export class HttpErrorHandler{handler=createErrorHandler();isDevelopment;constructor(options){this.isDevelopment=options?.isDevelopment
|
|
1
|
+
import{createErrorHandler,renderProductionErrorPage}from"./error-page";import{HttpError}from"./http-error";export{HttpError}from"./http-error";export class HttpErrorHandler{handler=createErrorHandler();isDevelopment;constructor(options){this.isDevelopment=options?.isDevelopment??process.env.NODE_ENV!=="production";if(options?.config)this.handler=createErrorHandler(options.config);this.handler.setFramework("Stacks")}setRequest(request){this.handler.setRequest(request);return this}setRouting(routing){this.handler.setRouting(routing);return this}addQuery(query,time,connection){this.handler.addQuery(query,time,connection);return this}async handle(error,status=500){if(this.isDevelopment)return this.handler.handleError(error,status);return new Response(renderProductionErrorPage(status),{status,headers:{"Content-Type":"text/html; charset=utf-8"}})}notFound(message){const error=new HttpError(404,message||"The requested resource could not be found.");return this.handle(error,404)}serverError(error){return this.handle(error,500)}forbidden(message){const error=new HttpError(403,message||"You do not have permission to access this resource.");return this.handle(error,403)}unauthorized(message){const error=new HttpError(401,message||"Authentication is required to access this resource.");return this.handle(error,401)}badRequest(message){const error=new HttpError(400,message||"The request was malformed or invalid.");return this.handle(error,400)}validationError(message){const error=new HttpError(422,message||"The request was well-formed but could not be processed.");return this.handle(error,422)}tooManyRequests(message){const error=new HttpError(429,message||"You have exceeded the rate limit.");return this.handle(error,429)}serviceUnavailable(message){const error=new HttpError(503,message||"The service is temporarily unavailable.");return this.handle(error,503)}}export function createHttpErrorHandler(options){return new HttpErrorHandler(options)}export async function renderHttpError(error,request,options){const handler=createHttpErrorHandler({isDevelopment:options?.isDevelopment,config:options?.config});if(request)handler.setRequest(request);return handler.handle(error,options?.status)}export function errorMiddleware(options){const handler=createHttpErrorHandler(options);return async(error,request)=>{handler.setRequest(request);let status=500;if(error instanceof HttpError)status=error.status;else if("status"in error&&typeof error.status==="number")status=error.status;else if("statusCode"in error&&typeof error.statusCode==="number")status=error.statusCode;return handler.handle(error,status)}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/error-handling",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.75.
|
|
4
|
+
"version": "0.75.257",
|
|
5
5
|
"description": "Type safe error handling.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -58,16 +58,16 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@bughq/sdk": "^0.3.0",
|
|
61
|
-
"@stacksjs/path": "0.75.
|
|
62
|
-
"@stacksjs/stx": "
|
|
63
|
-
"@stacksjs/types": "0.75.
|
|
61
|
+
"@stacksjs/path": "0.75.257",
|
|
62
|
+
"@stacksjs/stx": "0.2.644",
|
|
63
|
+
"@stacksjs/types": "0.75.257",
|
|
64
64
|
"ts-error-handling": "^0.1.3",
|
|
65
65
|
"ts-syntax-highlighter": "^0.2.17"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@stacksjs/cli": "0.75.
|
|
69
|
-
"@stacksjs/config": "0.75.
|
|
70
|
-
"@stacksjs/validation": "0.75.
|
|
68
|
+
"@stacksjs/cli": "0.75.257",
|
|
69
|
+
"@stacksjs/config": "0.75.257",
|
|
70
|
+
"@stacksjs/validation": "0.75.257",
|
|
71
71
|
"better-dx": "^0.2.24"
|
|
72
72
|
},
|
|
73
73
|
"sideEffects": false
|