@jaypie/express 1.2.4-rc15 → 1.2.4-rc17

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/esm/index.js CHANGED
@@ -932,6 +932,7 @@ function runExpressApp(app, req, res) {
932
932
  */
933
933
  function createLambdaHandler(app, _options) {
934
934
  return async (event, context) => {
935
+ let result;
935
936
  try {
936
937
  // Set current invoke for getCurrentInvokeUuid
937
938
  setCurrentInvoke(event, context);
@@ -941,8 +942,38 @@ function createLambdaHandler(app, _options) {
941
942
  const res = new LambdaResponseBuffered();
942
943
  // Run Express app
943
944
  await runExpressApp(app, req, res);
944
- // Return Lambda response
945
- return res.getResult();
945
+ // Get Lambda response - await explicitly to ensure we have the result
946
+ result = await res.getResult();
947
+ // Debug: Log the response before returning
948
+ console.log("[createLambdaHandler] Returning response:", JSON.stringify({
949
+ statusCode: result.statusCode,
950
+ headers: result.headers,
951
+ bodyLength: result.body?.length,
952
+ isBase64Encoded: result.isBase64Encoded,
953
+ }));
954
+ return result;
955
+ }
956
+ catch (error) {
957
+ // Log any unhandled errors
958
+ console.error("[createLambdaHandler] Unhandled error:", error);
959
+ if (error instanceof Error) {
960
+ console.error("[createLambdaHandler] Stack:", error.stack);
961
+ }
962
+ // Return a proper error response instead of throwing
963
+ return {
964
+ statusCode: 500,
965
+ headers: { "content-type": "application/json" },
966
+ body: JSON.stringify({
967
+ errors: [
968
+ {
969
+ status: 500,
970
+ title: "Internal Server Error",
971
+ detail: error instanceof Error ? error.message : "Unknown error occurred",
972
+ },
973
+ ],
974
+ }),
975
+ isBase64Encoded: false,
976
+ };
946
977
  }
947
978
  finally {
948
979
  // Clear current invoke context
@@ -1794,12 +1825,12 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1794
1825
  }
1795
1826
  }
1796
1827
  catch (error) {
1797
- log.fatal("Express encountered an error while sending the response");
1798
- log.var({ responseError: error });
1799
- // Log full stack trace for debugging
1800
- if (error instanceof Error && error.stack) {
1801
- log.error(error.stack);
1828
+ // Use console.error for raw stack trace to ensure it appears in CloudWatch
1829
+ if (error instanceof Error) {
1830
+ console.error("Express response error stack trace:", error.stack);
1802
1831
  }
1832
+ log.fatal(`Express encountered an error while sending the response: ${error instanceof Error ? error.message : String(error)}`);
1833
+ log.var({ responseError: error });
1803
1834
  }
1804
1835
  // Log response
1805
1836
  const extras = {};