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