sst-http 0.4.1 → 0.7.0

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
@@ -166,6 +166,7 @@ function normalizeRoutePath(path) {
166
166
  }
167
167
 
168
168
  // src/runtime.ts
169
+ var HTTP_ERROR_MARKER = Symbol.for("sst-http.HttpError");
169
170
  var HttpError = class extends Error {
170
171
  statusCode;
171
172
  headers;
@@ -173,6 +174,7 @@ var HttpError = class extends Error {
173
174
  constructor(statusCode, message, options2) {
174
175
  super(message);
175
176
  this.name = "HttpError";
177
+ Object.defineProperty(this, HTTP_ERROR_MARKER, { value: true });
176
178
  this.statusCode = statusCode;
177
179
  this.headers = options2?.headers;
178
180
  this.details = options2?.details;
@@ -408,8 +410,17 @@ function extractAuthClaims(event, entry) {
408
410
  const claims = ctxV2?.authorizer?.jwt?.claims || ctxV1?.authorizer?.claims;
409
411
  return claims ?? void 0;
410
412
  }
413
+ function isHttpError(error) {
414
+ if (!error || typeof error !== "object") {
415
+ return false;
416
+ }
417
+ const marker = error[HTTP_ERROR_MARKER] === true;
418
+ const named = error.name === "HttpError";
419
+ const status = typeof error.statusCode === "number";
420
+ return status && (marker || named);
421
+ }
411
422
  function handleError(error, preferV2) {
412
- if (error instanceof HttpError) {
423
+ if (isHttpError(error)) {
413
424
  return formatResponse({
414
425
  statusCode: error.statusCode,
415
426
  headers: {
package/dist/index.js CHANGED
@@ -119,6 +119,7 @@ function normalizeRoutePath(path) {
119
119
  }
120
120
 
121
121
  // src/runtime.ts
122
+ var HTTP_ERROR_MARKER = Symbol.for("sst-http.HttpError");
122
123
  var HttpError = class extends Error {
123
124
  statusCode;
124
125
  headers;
@@ -126,6 +127,7 @@ var HttpError = class extends Error {
126
127
  constructor(statusCode, message, options2) {
127
128
  super(message);
128
129
  this.name = "HttpError";
130
+ Object.defineProperty(this, HTTP_ERROR_MARKER, { value: true });
129
131
  this.statusCode = statusCode;
130
132
  this.headers = options2?.headers;
131
133
  this.details = options2?.details;
@@ -361,8 +363,17 @@ function extractAuthClaims(event, entry) {
361
363
  const claims = ctxV2?.authorizer?.jwt?.claims || ctxV1?.authorizer?.claims;
362
364
  return claims ?? void 0;
363
365
  }
366
+ function isHttpError(error) {
367
+ if (!error || typeof error !== "object") {
368
+ return false;
369
+ }
370
+ const marker = error[HTTP_ERROR_MARKER] === true;
371
+ const named = error.name === "HttpError";
372
+ const status = typeof error.statusCode === "number";
373
+ return status && (marker || named);
374
+ }
364
375
  function handleError(error, preferV2) {
365
- if (error instanceof HttpError) {
376
+ if (isHttpError(error)) {
366
377
  return formatResponse({
367
378
  statusCode: error.statusCode,
368
379
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst-http",
3
- "version": "0.4.1",
3
+ "version": "0.7.0",
4
4
  "description": "Decorator-based routing for SST v3 with a single Lambda and Firebase JWT authorizer.",
5
5
  "license": "MIT",
6
6
  "author": "",