@replayio-app-building/netlify-recorder 0.23.0 → 0.24.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.
Files changed (2) hide show
  1. package/dist/index.js +44 -36
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -827,45 +827,53 @@ async function createRequestRecording(blobUrlOrData, handlerPath, requestInfo) {
827
827
  );
828
828
  }
829
829
  let rawResult;
830
- if (isV2) {
831
- const url = requestInfo.rawUrl ?? `https://localhost${requestInfo.url}`;
832
- const reqInit = {
833
- method: requestInfo.method,
834
- headers: requestInfo.headers
835
- };
836
- if (requestInfo.body && requestInfo.method !== "GET" && requestInfo.method !== "HEAD") {
837
- reqInit.body = requestInfo.body;
838
- }
839
- const RequestCtor = globalThis.Request;
840
- if (!RequestCtor) {
841
- throw new Error(
842
- "Handler uses Netlify Functions v2 signature but Request is not available in this environment. Ensure undici or a Request polyfill is installed."
843
- );
844
- }
845
- const req = new RequestCtor(url, reqInit);
846
- const context = { geo: {}, ip: "127.0.0.1", requestId: "replay", server: { region: "local" } };
847
- const response = await handler(req, context);
848
- if (response && typeof response === "object" && typeof response.status === "number" && typeof response.text === "function") {
849
- const res = response;
850
- rawResult = {
851
- statusCode: res.status,
852
- body: await res.text()
830
+ try {
831
+ if (isV2) {
832
+ const url = requestInfo.rawUrl ?? `https://localhost${requestInfo.url}`;
833
+ const reqInit = {
834
+ method: requestInfo.method,
835
+ headers: requestInfo.headers
853
836
  };
837
+ if (requestInfo.body && requestInfo.method !== "GET" && requestInfo.method !== "HEAD") {
838
+ reqInit.body = requestInfo.body;
839
+ }
840
+ const RequestCtor = globalThis.Request;
841
+ if (!RequestCtor) {
842
+ throw new Error(
843
+ "Handler uses Netlify Functions v2 signature but Request is not available in this environment. Ensure undici or a Request polyfill is installed."
844
+ );
845
+ }
846
+ const req = new RequestCtor(url, reqInit);
847
+ const context = { geo: {}, ip: "127.0.0.1", requestId: "replay", server: { region: "local" } };
848
+ const response = await handler(req, context);
849
+ if (response && typeof response === "object" && typeof response.status === "number" && typeof response.text === "function") {
850
+ const res = response;
851
+ rawResult = {
852
+ statusCode: res.status,
853
+ body: await res.text()
854
+ };
855
+ } else {
856
+ rawResult = response;
857
+ }
854
858
  } else {
855
- rawResult = response;
859
+ rawResult = await handler({
860
+ httpMethod: requestInfo.method,
861
+ path: requestInfo.url,
862
+ headers: requestInfo.headers,
863
+ body: requestInfo.body ?? null,
864
+ queryStringParameters: requestInfo.queryStringParameters ?? null,
865
+ multiValueQueryStringParameters: requestInfo.multiValueQueryStringParameters ?? null,
866
+ rawUrl: requestInfo.rawUrl ?? requestInfo.url,
867
+ rawQuery: requestInfo.rawQuery ?? "",
868
+ isBase64Encoded: requestInfo.isBase64Encoded ?? false
869
+ });
856
870
  }
857
- } else {
858
- rawResult = await handler({
859
- httpMethod: requestInfo.method,
860
- path: requestInfo.url,
861
- headers: requestInfo.headers,
862
- body: requestInfo.body ?? null,
863
- queryStringParameters: requestInfo.queryStringParameters ?? null,
864
- multiValueQueryStringParameters: requestInfo.multiValueQueryStringParameters ?? null,
865
- rawUrl: requestInfo.rawUrl ?? requestInfo.url,
866
- rawQuery: requestInfo.rawQuery ?? "",
867
- isBase64Encoded: requestInfo.isBase64Encoded ?? false
868
- });
871
+ } catch (handlerErr) {
872
+ const errorMessage = handlerErr instanceof Error ? handlerErr.message : String(handlerErr);
873
+ rawResult = {
874
+ statusCode: 500,
875
+ body: JSON.stringify({ error: errorMessage })
876
+ };
869
877
  }
870
878
  if (blobData.handlerResponse) {
871
879
  const replayRes = rawResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayio-app-building/netlify-recorder",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Capture and replay Netlify function executions as Replay recordings",
5
5
  "type": "module",
6
6
  "exports": {