h3 0.7.10 → 0.7.11

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/index.cjs CHANGED
@@ -82,7 +82,7 @@ function handleCacheHeaders(event, opts) {
82
82
  const cacheControls = ["public"].concat(opts.cacheControls || []);
83
83
  let cacheMatched = false;
84
84
  if (opts.maxAge !== void 0) {
85
- opts.cacheControls?.push(`max-age=${+opts.maxAge}`, `s-maxage=${+opts.maxAge}`);
85
+ cacheControls.push(`max-age=${+opts.maxAge}`, `s-maxage=${+opts.maxAge}`);
86
86
  }
87
87
  if (opts.modifiedTime) {
88
88
  const modifiedTime = new Date(opts.modifiedTime);
@@ -183,6 +183,8 @@ class H3Error extends Error {
183
183
  constructor() {
184
184
  super(...arguments);
185
185
  this.statusCode = 500;
186
+ this.fatal = false;
187
+ this.unhandled = false;
186
188
  this.statusMessage = "Internal Server Error";
187
189
  }
188
190
  }
@@ -203,6 +205,12 @@ function createError(input) {
203
205
  if (input.data) {
204
206
  err.data = input.data;
205
207
  }
208
+ if (input.fatal !== void 0) {
209
+ err.fatal = input.fatal;
210
+ }
211
+ if (input.unhandled !== void 0) {
212
+ err.unhandled = input.unhandled;
213
+ }
206
214
  return err;
207
215
  }
208
216
  function sendError(event, error, debug) {
@@ -376,14 +384,18 @@ function createApp(options = {}) {
376
384
  const event = createEvent(req, res);
377
385
  try {
378
386
  await handler(event);
379
- } catch (err) {
387
+ } catch (_error) {
388
+ const error = createError(_error);
389
+ if (!isError(_error)) {
390
+ error.unhandled = true;
391
+ }
392
+ if (error.unhandled || error.fatal) {
393
+ console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
394
+ }
380
395
  if (options.onError) {
381
- await options.onError(err, event);
396
+ await options.onError(error, event);
382
397
  } else {
383
- if (!isError(err)) {
384
- console.error("[h3]", err);
385
- }
386
- await sendError(event, err, !!options.debug);
398
+ await sendError(event, error, !!options.debug);
387
399
  }
388
400
  }
389
401
  };
package/dist/index.d.ts CHANGED
@@ -98,12 +98,16 @@ declare function createAppEventHandler(stack: Stack, options: AppOptions): Event
98
98
  * @extends Error
99
99
  * @property {Number} statusCode An Integer indicating the HTTP response status code.
100
100
  * @property {String} statusMessage A String representing the HTTP status message
101
+ * @property {String} fatal Indicates if the error is a fatal error.
102
+ * @property {String} unhandled Indicates if the error was unhandled and auto captured.
101
103
  * @property {Any} data An extra data that will includes in the response.<br>
102
104
  * This can be used to pass additional information about the error.
103
105
  * @property {Boolean} internal Setting this property to <code>true</code> will mark error as an internal error
104
106
  */
105
107
  declare class H3Error extends Error {
106
108
  statusCode: number;
109
+ fatal: boolean;
110
+ unhandled: boolean;
107
111
  statusMessage: string;
108
112
  data?: any;
109
113
  }
package/dist/index.mjs CHANGED
@@ -74,7 +74,7 @@ function handleCacheHeaders(event, opts) {
74
74
  const cacheControls = ["public"].concat(opts.cacheControls || []);
75
75
  let cacheMatched = false;
76
76
  if (opts.maxAge !== void 0) {
77
- opts.cacheControls?.push(`max-age=${+opts.maxAge}`, `s-maxage=${+opts.maxAge}`);
77
+ cacheControls.push(`max-age=${+opts.maxAge}`, `s-maxage=${+opts.maxAge}`);
78
78
  }
79
79
  if (opts.modifiedTime) {
80
80
  const modifiedTime = new Date(opts.modifiedTime);
@@ -175,6 +175,8 @@ class H3Error extends Error {
175
175
  constructor() {
176
176
  super(...arguments);
177
177
  this.statusCode = 500;
178
+ this.fatal = false;
179
+ this.unhandled = false;
178
180
  this.statusMessage = "Internal Server Error";
179
181
  }
180
182
  }
@@ -195,6 +197,12 @@ function createError(input) {
195
197
  if (input.data) {
196
198
  err.data = input.data;
197
199
  }
200
+ if (input.fatal !== void 0) {
201
+ err.fatal = input.fatal;
202
+ }
203
+ if (input.unhandled !== void 0) {
204
+ err.unhandled = input.unhandled;
205
+ }
198
206
  return err;
199
207
  }
200
208
  function sendError(event, error, debug) {
@@ -368,14 +376,18 @@ function createApp(options = {}) {
368
376
  const event = createEvent(req, res);
369
377
  try {
370
378
  await handler(event);
371
- } catch (err) {
379
+ } catch (_error) {
380
+ const error = createError(_error);
381
+ if (!isError(_error)) {
382
+ error.unhandled = true;
383
+ }
384
+ if (error.unhandled || error.fatal) {
385
+ console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
386
+ }
372
387
  if (options.onError) {
373
- await options.onError(err, event);
388
+ await options.onError(error, event);
374
389
  } else {
375
- if (!isError(err)) {
376
- console.error("[h3]", err);
377
- }
378
- await sendError(event, err, !!options.debug);
390
+ await sendError(event, error, !!options.debug);
379
391
  }
380
392
  }
381
393
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
4
4
  "description": "Tiny JavaScript Server",
5
5
  "repository": "unjs/h3",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  "cookie-es": "^0.5.0",
23
23
  "destr": "^1.1.1",
24
24
  "radix3": "^0.1.2",
25
- "ufo": "^0.8.4"
25
+ "ufo": "^0.8.5"
26
26
  },
27
27
  "devDependencies": {
28
28
  "0x": "latest",
@@ -45,7 +45,7 @@
45
45
  "unbuild": "latest",
46
46
  "vitest": "latest"
47
47
  },
48
- "packageManager": "pnpm@7.2.1",
48
+ "packageManager": "pnpm@7.5.2",
49
49
  "scripts": {
50
50
  "build": "unbuild",
51
51
  "dev": "vitest",