@tramvai/module-render 2.20.0 → 2.20.1

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/lib/server.es.js CHANGED
@@ -824,24 +824,38 @@ RenderModule = RenderModule_1 = __decorate([
824
824
  html = await htmlBuilder.flow();
825
825
  }
826
826
  catch (error) {
827
- const requestInfo = {
828
- ip: requestManager.getClientIp(),
829
- requestId: requestManager.getHeader('x-request-id'),
830
- url: requestManager.getUrl(),
831
- };
832
- log.error({
833
- event: 'send-server-error',
834
- message: 'Page render error, switch to fallback',
835
- error,
836
- requestInfo,
837
- });
838
- // Assuming that there was an error when rendering the page, try to render again with ErrorBoundary
839
- context.dispatch(setPageErrorEvent(error));
840
- html = await htmlBuilder.flow();
827
+ // assuming that there was an error when rendering the page, try to render again with ErrorBoundary
828
+ try {
829
+ log.info({ event: 'render-page-boundary-start' });
830
+ context.dispatch(setPageErrorEvent(error));
831
+ html = await htmlBuilder.flow();
832
+ log.info({ event: 'render-page-boundary-success' });
833
+ }
834
+ catch (e) {
835
+ log.warn({ event: 'render-page-boundary-error', error: e });
836
+ // pass page render error to default error handler,
837
+ // send-server-error event will be logged with this error
838
+ throw error;
839
+ }
841
840
  }
842
841
  const pageRenderError = context.getState(PageErrorStore);
842
+ // log send-server-error only after successful Page Boundary render,
843
+ // otherwise this event will be logged in default error handler
843
844
  if (pageRenderError) {
844
845
  const status = pageRenderError.status || pageRenderError.httpStatus || 500;
846
+ if (status >= 500) {
847
+ const requestInfo = {
848
+ ip: requestManager.getClientIp(),
849
+ requestId: requestManager.getHeader('x-request-id'),
850
+ url: requestManager.getUrl(),
851
+ };
852
+ log.error({
853
+ event: 'send-server-error',
854
+ message: 'Page render error, switch to page boundary',
855
+ error: deserializeError(pageRenderError),
856
+ requestInfo,
857
+ });
858
+ }
845
859
  responseManager.setStatus(status);
846
860
  }
847
861
  // Проставляем не кэширующие заголовки
@@ -940,9 +954,26 @@ RenderModule = RenderModule_1 = __decorate([
940
954
  }
941
955
  let body;
942
956
  try {
943
- log.info({ event: 'render-root-boundary' });
957
+ log.info({ event: 'render-root-boundary-start' });
944
958
  body = renderToString(createElement(RootErrorBoundary, { error, url: parse(request.url) }));
945
- reply.status(error.httpStatus || error.status || 500);
959
+ log.info({ event: 'render-root-boundary-success' });
960
+ const status = error.status || error.httpStatus || 500;
961
+ // log send-server-error only after successful Root Boundary render,
962
+ // otherwise this event will be logged in default error handler
963
+ if (status >= 500) {
964
+ const requestInfo = {
965
+ ip: request.headers['x-real-ip'],
966
+ requestId: request.headers['x-request-id'],
967
+ url: request.url,
968
+ };
969
+ log.error({
970
+ event: 'send-server-error',
971
+ message: 'Page render error, switch to root boundary',
972
+ error,
973
+ requestInfo,
974
+ });
975
+ }
976
+ reply.status(status);
946
977
  reply.header('Content-Type', 'text/html; charset=utf-8');
947
978
  reply.header('Content-Length', Buffer.byteLength(body, 'utf8'));
948
979
  reply.header('Cache-Control', 'no-cache, no-store, must-revalidate');
package/lib/server.js CHANGED
@@ -860,24 +860,38 @@ exports.RenderModule = RenderModule_1 = tslib.__decorate([
860
860
  html = await htmlBuilder.flow();
861
861
  }
862
862
  catch (error) {
863
- const requestInfo = {
864
- ip: requestManager.getClientIp(),
865
- requestId: requestManager.getHeader('x-request-id'),
866
- url: requestManager.getUrl(),
867
- };
868
- log.error({
869
- event: 'send-server-error',
870
- message: 'Page render error, switch to fallback',
871
- error,
872
- requestInfo,
873
- });
874
- // Assuming that there was an error when rendering the page, try to render again with ErrorBoundary
875
- context.dispatch(setPageErrorEvent(error));
876
- html = await htmlBuilder.flow();
863
+ // assuming that there was an error when rendering the page, try to render again with ErrorBoundary
864
+ try {
865
+ log.info({ event: 'render-page-boundary-start' });
866
+ context.dispatch(setPageErrorEvent(error));
867
+ html = await htmlBuilder.flow();
868
+ log.info({ event: 'render-page-boundary-success' });
869
+ }
870
+ catch (e) {
871
+ log.warn({ event: 'render-page-boundary-error', error: e });
872
+ // pass page render error to default error handler,
873
+ // send-server-error event will be logged with this error
874
+ throw error;
875
+ }
877
876
  }
878
877
  const pageRenderError = context.getState(PageErrorStore);
878
+ // log send-server-error only after successful Page Boundary render,
879
+ // otherwise this event will be logged in default error handler
879
880
  if (pageRenderError) {
880
881
  const status = pageRenderError.status || pageRenderError.httpStatus || 500;
882
+ if (status >= 500) {
883
+ const requestInfo = {
884
+ ip: requestManager.getClientIp(),
885
+ requestId: requestManager.getHeader('x-request-id'),
886
+ url: requestManager.getUrl(),
887
+ };
888
+ log.error({
889
+ event: 'send-server-error',
890
+ message: 'Page render error, switch to page boundary',
891
+ error: deserializeError(pageRenderError),
892
+ requestInfo,
893
+ });
894
+ }
881
895
  responseManager.setStatus(status);
882
896
  }
883
897
  // Проставляем не кэширующие заголовки
@@ -976,9 +990,26 @@ exports.RenderModule = RenderModule_1 = tslib.__decorate([
976
990
  }
977
991
  let body;
978
992
  try {
979
- log.info({ event: 'render-root-boundary' });
993
+ log.info({ event: 'render-root-boundary-start' });
980
994
  body = server$1.renderToString(react.createElement(RootErrorBoundary, { error, url: url.parse(request.url) }));
981
- reply.status(error.httpStatus || error.status || 500);
995
+ log.info({ event: 'render-root-boundary-success' });
996
+ const status = error.status || error.httpStatus || 500;
997
+ // log send-server-error only after successful Root Boundary render,
998
+ // otherwise this event will be logged in default error handler
999
+ if (status >= 500) {
1000
+ const requestInfo = {
1001
+ ip: request.headers['x-real-ip'],
1002
+ requestId: request.headers['x-request-id'],
1003
+ url: request.url,
1004
+ };
1005
+ log.error({
1006
+ event: 'send-server-error',
1007
+ message: 'Page render error, switch to root boundary',
1008
+ error,
1009
+ requestInfo,
1010
+ });
1011
+ }
1012
+ reply.status(status);
982
1013
  reply.header('Content-Type', 'text/html; charset=utf-8');
983
1014
  reply.header('Content-Length', Buffer.byteLength(body, 'utf8'));
984
1015
  reply.header('Cache-Control', 'no-cache, no-store, must-revalidate');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-render",
3
- "version": "2.20.0",
3
+ "version": "2.20.1",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -24,13 +24,13 @@
24
24
  "@tinkoff/htmlpagebuilder": "0.5.2",
25
25
  "@tinkoff/layout-factory": "0.3.2",
26
26
  "@tinkoff/url": "0.8.2",
27
- "@tinkoff/user-agent": "0.4.51",
28
- "@tramvai/module-client-hints": "2.20.0",
29
- "@tramvai/module-router": "2.20.0",
30
- "@tramvai/react": "2.20.0",
27
+ "@tinkoff/user-agent": "0.4.52",
28
+ "@tramvai/module-client-hints": "2.20.1",
29
+ "@tramvai/module-router": "2.20.1",
30
+ "@tramvai/react": "2.20.1",
31
31
  "@tramvai/safe-strings": "0.5.2",
32
- "@tramvai/tokens-render": "2.20.0",
33
- "@tramvai/experiments": "2.20.0",
32
+ "@tramvai/tokens-render": "2.20.1",
33
+ "@tramvai/experiments": "2.20.1",
34
34
  "@types/loadable__server": "^5.12.6",
35
35
  "node-fetch": "^2.6.1"
36
36
  },
@@ -38,14 +38,14 @@
38
38
  "@tinkoff/dippy": "0.8.2",
39
39
  "@tinkoff/utils": "^2.1.2",
40
40
  "@tinkoff/react-hooks": "0.1.2",
41
- "@tramvai/cli": "2.20.0",
42
- "@tramvai/core": "2.20.0",
43
- "@tramvai/module-common": "2.20.0",
44
- "@tramvai/state": "2.20.0",
45
- "@tramvai/test-helpers": "2.20.0",
46
- "@tramvai/tokens-common": "2.20.0",
47
- "@tramvai/tokens-router": "2.20.0",
48
- "@tramvai/tokens-server-private": "2.20.0",
41
+ "@tramvai/cli": "2.20.1",
42
+ "@tramvai/core": "2.20.1",
43
+ "@tramvai/module-common": "2.20.1",
44
+ "@tramvai/state": "2.20.1",
45
+ "@tramvai/test-helpers": "2.20.1",
46
+ "@tramvai/tokens-common": "2.20.1",
47
+ "@tramvai/tokens-router": "2.20.1",
48
+ "@tramvai/tokens-server-private": "2.20.1",
49
49
  "express": "^4.17.1",
50
50
  "prop-types": "^15.6.2",
51
51
  "react": ">=16.14.0",