lambder 3.2.4 → 3.2.6

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/Lambder.js CHANGED
@@ -431,22 +431,26 @@ export default class Lambder {
431
431
  }
432
432
  catch (err) {
433
433
  const wrappedError = err instanceof Error ? err : new Error("Error: " + String(err));
434
+ // ctx may be null (createContext failed): derive the format from the raw event.
435
+ const eventFormat = ctx?._otherInternal.eventFormat ?? (isV2HttpEvent(event) ? "v2" : "v1");
434
436
  try {
435
437
  if (this.globalErrorHandler) {
436
438
  const responseBuilder = this.getResponseBuilder(ctx ?? undefined);
437
439
  const errorResponse = await this.globalErrorHandler(wrappedError, ctx, responseBuilder, ctx?._otherInternal.logToApiResponseAccumulator);
438
- return await finalizeResponse(ctx, errorResponse, this.finalizeOptions, ctx?._otherInternal.eventFormat ?? "v1");
440
+ return await finalizeResponse(ctx, errorResponse, this.finalizeOptions, eventFormat);
439
441
  }
440
442
  }
441
443
  catch (handlerErr) {
442
444
  if (handlerErr instanceof LambderResponse) {
443
445
  try {
444
- return await finalizeResponse(ctx, handlerErr, this.finalizeOptions, ctx?._otherInternal.eventFormat ?? "v1");
446
+ return await finalizeResponse(ctx, handlerErr, this.finalizeOptions, eventFormat);
445
447
  }
446
448
  catch { /* fall through */ }
447
449
  }
448
450
  }
449
- return { statusCode: 500, multiValueHeaders: {}, body: "Internal Server Error.", isBase64Encoded: false };
451
+ return eventFormat === "v2"
452
+ ? { statusCode: 500, headers: {}, body: "Internal Server Error.", isBase64Encoded: false }
453
+ : { statusCode: 500, multiValueHeaders: {}, body: "Internal Server Error.", isBase64Encoded: false };
450
454
  }
451
455
  }
452
456
  }
@@ -16,6 +16,11 @@ export const createContext = (event, lambdaContext, apiPath) => {
16
16
  if (isV2HttpEvent(event)) {
17
17
  host = headers.host || event.requestContext.domainName || "";
18
18
  path = event.rawPath;
19
+ // Named stages (non-$default) are included in rawPath; v1 strips them.
20
+ const stage = event.requestContext.stage;
21
+ if (stage && stage !== "$default" && (path === `/${stage}` || path.startsWith(`/${stage}/`))) {
22
+ path = path.slice(stage.length + 1) || "/";
23
+ }
19
24
  method = event.requestContext.http.method;
20
25
  get = {};
21
26
  for (const [key, value] of new URLSearchParams(event.rawQueryString ?? "").entries()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "3.2.4",
3
+ "version": "3.2.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",