@jaypie/express 1.2.4-rc22 → 1.2.4-rc23
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { OutgoingHttpHeaders } from "node:http";
|
|
2
2
|
import { Writable } from "node:stream";
|
|
3
3
|
import type { LambdaResponse } from "./types.js";
|
|
4
|
+
export declare const JAYPIE_LAMBDA_MOCK: unique symbol;
|
|
4
5
|
/**
|
|
5
6
|
* Mock ServerResponse that buffers the response.
|
|
6
7
|
* Collects status, headers, and body chunks, then returns a Lambda response.
|
package/dist/esm/index.js
CHANGED
|
@@ -186,6 +186,9 @@ function createLambdaRequest(event, context) {
|
|
|
186
186
|
//
|
|
187
187
|
// Constants
|
|
188
188
|
//
|
|
189
|
+
// Symbol to identify Lambda mock responses. Uses Symbol.for() to ensure
|
|
190
|
+
// the same symbol is used across bundles/realms. Survives prototype manipulation.
|
|
191
|
+
const JAYPIE_LAMBDA_MOCK = Symbol.for("@jaypie/express/LambdaMock");
|
|
189
192
|
// Get Node's internal kOutHeaders symbol from ServerResponse prototype.
|
|
190
193
|
// This is needed for compatibility with Datadog dd-trace instrumentation,
|
|
191
194
|
// which patches HTTP methods and expects this internal state to exist.
|
|
@@ -223,6 +226,8 @@ class LambdaResponseBuffered extends Writable {
|
|
|
223
226
|
this._headers = new Map();
|
|
224
227
|
this._headersSent = false;
|
|
225
228
|
this._resolve = null;
|
|
229
|
+
// Mark as Lambda mock response for identification in expressHandler
|
|
230
|
+
this[JAYPIE_LAMBDA_MOCK] = true;
|
|
226
231
|
// Initialize Node's internal kOutHeaders for dd-trace compatibility.
|
|
227
232
|
// dd-trace patches HTTP methods and expects this internal state.
|
|
228
233
|
if (kOutHeaders$1) {
|
|
@@ -1505,12 +1510,10 @@ const logger$1 = log;
|
|
|
1505
1510
|
//
|
|
1506
1511
|
/**
|
|
1507
1512
|
* Check if response is a Lambda mock response with direct internal access.
|
|
1513
|
+
* Uses Symbol marker to survive prototype chain modifications from Express and dd-trace.
|
|
1508
1514
|
*/
|
|
1509
1515
|
function isLambdaMockResponse(res) {
|
|
1510
|
-
|
|
1511
|
-
return (mock._headers instanceof Map &&
|
|
1512
|
-
Array.isArray(mock._chunks) &&
|
|
1513
|
-
typeof mock.buildResult === "function");
|
|
1516
|
+
return res[JAYPIE_LAMBDA_MOCK] === true;
|
|
1514
1517
|
}
|
|
1515
1518
|
/**
|
|
1516
1519
|
* Safely send a JSON response, avoiding dd-trace interception.
|
|
@@ -1836,10 +1839,17 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
|
|
|
1836
1839
|
}
|
|
1837
1840
|
catch (error) {
|
|
1838
1841
|
// Use console.error for raw stack trace to ensure it appears in CloudWatch
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1842
|
+
// Handle both Error objects and plain thrown values
|
|
1843
|
+
const errorMessage = error instanceof Error
|
|
1844
|
+
? error.message
|
|
1845
|
+
: typeof error === "object" && error !== null
|
|
1846
|
+
? JSON.stringify(error)
|
|
1847
|
+
: String(error);
|
|
1848
|
+
const errorStack = error instanceof Error
|
|
1849
|
+
? error.stack
|
|
1850
|
+
: new Error("Stack trace").stack?.replace("Error: Stack trace", `Error: ${errorMessage}`);
|
|
1851
|
+
console.error("Express response error stack trace:", errorStack);
|
|
1852
|
+
log.fatal(`Express encountered an error while sending the response: ${errorMessage}`);
|
|
1843
1853
|
log.var({ responseError: error });
|
|
1844
1854
|
}
|
|
1845
1855
|
// Log response
|