Comparing version 0.2.2 to 0.2.3
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.2.3](https://github.com/nuxt-contrib/h3/compare/v0.2.2...v0.2.3) (2021-01-20) | ||
### Bug Fixes | ||
* improve internal error handling ([b38d450](https://github.com/nuxt-contrib/h3/commit/b38d450e39101104333f33516d75869cd2427f9d)) | ||
### [0.2.2](https://github.com/nuxt-contrib/h3/compare/v0.2.1...v0.2.2) (2021-01-20) | ||
@@ -7,0 +14,0 @@ |
@@ -69,3 +69,2 @@ import { IncomingMessage, ServerResponse } from 'http'; | ||
data?: any; | ||
internal: boolean; | ||
} | ||
@@ -72,0 +71,0 @@ /** |
@@ -464,4 +464,3 @@ 'use strict'; | ||
this.statusCode = 500; | ||
this.statusMessage = "Internal Error"; | ||
this.internal = false; | ||
this.statusMessage = "H3Error"; | ||
} | ||
@@ -474,3 +473,2 @@ } | ||
const err = new H3Error(input.message); | ||
Error.captureStackTrace(err, createError); | ||
if (input.statusCode) { | ||
@@ -485,12 +483,15 @@ err.statusCode = input.statusCode; | ||
} | ||
if (input.internal) { | ||
err.internal = input.internal; | ||
} | ||
return err; | ||
} | ||
function sendError(res, error, debug) { | ||
const h3Error = createError(error); | ||
if (h3Error.internal) { | ||
console.error(h3Error); | ||
let h3Error; | ||
if (error instanceof H3Error) { | ||
h3Error = error; | ||
} else { | ||
console.error(error); | ||
h3Error = createError(error); | ||
} | ||
if (res.writableEnded) { | ||
return; | ||
} | ||
res.statusCode = h3Error.statusCode; | ||
@@ -519,5 +520,2 @@ res.statusMessage = h3Error.statusMessage; | ||
} | ||
if (typeof error2.internal === "undefined") { | ||
error2.internal = true; | ||
} | ||
return sendError(res, error2, !!options.debug); | ||
@@ -560,10 +558,3 @@ }); | ||
} | ||
let val; | ||
try { | ||
val = await layer.handle(req, res); | ||
} catch (err) { | ||
if (!res.writableEnded) { | ||
return sendError(res, err, true); | ||
} | ||
} | ||
const val = await layer.handle(req, res); | ||
if (res.writableEnded) { | ||
@@ -586,3 +577,3 @@ break; | ||
if (!res.writableEnded) { | ||
return sendError(res, createError({statusCode: 404, statusMessage: "Not Found"}), false); | ||
throw createError({statusCode: 404, statusMessage: "Not Found"}); | ||
} | ||
@@ -589,0 +580,0 @@ }; |
{ | ||
"name": "h3", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Tiny JavaScript Server", | ||
@@ -5,0 +5,0 @@ "repository": "nuxt-contrib/h3", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51499
1250