@tramvai/module-router 1.82.2 → 1.82.3
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/index.es.js +16 -7
- package/lib/index.js +15 -6
- package/package.json +16 -16
package/lib/index.es.js
CHANGED
|
@@ -15,7 +15,7 @@ import replace from '@tinkoff/utils/string/replace';
|
|
|
15
15
|
import React from 'react';
|
|
16
16
|
import { isFileSystemPageComponent, fileSystemPagesEnabled, getStaticFileSystemPages, fileSystemPageToRoute } from '@tramvai/experiments';
|
|
17
17
|
import uniq from '@tinkoff/utils/array/uniq';
|
|
18
|
-
import { isRedirectFoundError, isNotFoundError,
|
|
18
|
+
import { isRedirectFoundError, isNotFoundError, throwRedirectFoundError, HttpError, makeErrorSilent } from '@tinkoff/errors';
|
|
19
19
|
import { SERVER_MODULE_PAPI_PUBLIC_ROUTE } from '@tramvai/tokens-server';
|
|
20
20
|
import prop from '@tinkoff/utils/object/prop';
|
|
21
21
|
import { createPapiMethod } from '@tramvai/papi';
|
|
@@ -500,24 +500,33 @@ const serverHooks = [
|
|
|
500
500
|
];
|
|
501
501
|
|
|
502
502
|
const routerOptions = ({ requestManager, responseManager, }) => {
|
|
503
|
-
const
|
|
504
|
-
|
|
503
|
+
const getUrl = (navigation) => { var _a, _b; return (_b = (_a = navigation.url) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : requestManager.getUrl(); };
|
|
504
|
+
const throwError = ({ defaultStatus, url, silent, }) => {
|
|
505
|
+
const error = new HttpError({
|
|
506
|
+
url,
|
|
505
507
|
httpStatus: responseManager.getStatus() >= 300 ? responseManager.getStatus() : defaultStatus,
|
|
506
508
|
});
|
|
509
|
+
if (silent) {
|
|
510
|
+
makeErrorSilent(error);
|
|
511
|
+
}
|
|
512
|
+
throw error;
|
|
507
513
|
};
|
|
508
514
|
return {
|
|
509
|
-
onNotFound: async () => {
|
|
510
|
-
|
|
515
|
+
onNotFound: async (navigation) => {
|
|
516
|
+
// isSilent is used to prevent command line error logs,
|
|
517
|
+
// because 404 errors is expected behavior
|
|
518
|
+
throwError({ defaultStatus: 404, url: getUrl(navigation), silent: true });
|
|
511
519
|
},
|
|
512
520
|
onRedirect: async (navigation) => {
|
|
513
521
|
const { fromUrl, url, code } = navigation;
|
|
514
522
|
throwRedirectFoundError({
|
|
523
|
+
url: getUrl(navigation),
|
|
515
524
|
nextUrl: fromUrl.origin !== url.origin ? url.href : url.path,
|
|
516
525
|
httpStatus: code,
|
|
517
526
|
});
|
|
518
527
|
},
|
|
519
|
-
onBlock: async () => {
|
|
520
|
-
throwError(500);
|
|
528
|
+
onBlock: async (navigation) => {
|
|
529
|
+
throwError({ defaultStatus: 500, url: getUrl(navigation) });
|
|
521
530
|
},
|
|
522
531
|
defaultRedirectCode: requestManager.getMethod() === 'GET' ? 301 : 308,
|
|
523
532
|
};
|
package/lib/index.js
CHANGED
|
@@ -512,24 +512,33 @@ const serverHooks = [
|
|
|
512
512
|
];
|
|
513
513
|
|
|
514
514
|
const routerOptions = ({ requestManager, responseManager, }) => {
|
|
515
|
-
const
|
|
516
|
-
|
|
515
|
+
const getUrl = (navigation) => { var _a, _b; return (_b = (_a = navigation.url) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : requestManager.getUrl(); };
|
|
516
|
+
const throwError = ({ defaultStatus, url, silent, }) => {
|
|
517
|
+
const error = new errors.HttpError({
|
|
518
|
+
url,
|
|
517
519
|
httpStatus: responseManager.getStatus() >= 300 ? responseManager.getStatus() : defaultStatus,
|
|
518
520
|
});
|
|
521
|
+
if (silent) {
|
|
522
|
+
errors.makeErrorSilent(error);
|
|
523
|
+
}
|
|
524
|
+
throw error;
|
|
519
525
|
};
|
|
520
526
|
return {
|
|
521
|
-
onNotFound: async () => {
|
|
522
|
-
|
|
527
|
+
onNotFound: async (navigation) => {
|
|
528
|
+
// isSilent is used to prevent command line error logs,
|
|
529
|
+
// because 404 errors is expected behavior
|
|
530
|
+
throwError({ defaultStatus: 404, url: getUrl(navigation), silent: true });
|
|
523
531
|
},
|
|
524
532
|
onRedirect: async (navigation) => {
|
|
525
533
|
const { fromUrl, url, code } = navigation;
|
|
526
534
|
errors.throwRedirectFoundError({
|
|
535
|
+
url: getUrl(navigation),
|
|
527
536
|
nextUrl: fromUrl.origin !== url.origin ? url.href : url.path,
|
|
528
537
|
httpStatus: code,
|
|
529
538
|
});
|
|
530
539
|
},
|
|
531
|
-
onBlock: async () => {
|
|
532
|
-
throwError(500);
|
|
540
|
+
onBlock: async (navigation) => {
|
|
541
|
+
throwError({ defaultStatus: 500, url: getUrl(navigation) });
|
|
533
542
|
},
|
|
534
543
|
defaultRedirectCode: requestManager.getMethod() === 'GET' ? 301 : 308,
|
|
535
544
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-router",
|
|
3
|
-
"version": "1.82.
|
|
3
|
+
"version": "1.82.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"browser": {
|
|
@@ -22,26 +22,26 @@
|
|
|
22
22
|
"build-for-publish": "true"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tinkoff/errors": "0.2.
|
|
25
|
+
"@tinkoff/errors": "0.2.20",
|
|
26
26
|
"@tinkoff/router": "0.1.71",
|
|
27
27
|
"@tinkoff/url": "0.7.37",
|
|
28
|
-
"@tramvai/tokens-child-app": "1.82.
|
|
29
|
-
"@tramvai/tokens-render": "1.82.
|
|
30
|
-
"@tramvai/tokens-router": "1.82.
|
|
31
|
-
"@tramvai/tokens-server": "1.82.
|
|
32
|
-
"@tramvai/experiments": "1.82.
|
|
28
|
+
"@tramvai/tokens-child-app": "1.82.3",
|
|
29
|
+
"@tramvai/tokens-render": "1.82.3",
|
|
30
|
+
"@tramvai/tokens-router": "1.82.3",
|
|
31
|
+
"@tramvai/tokens-server": "1.82.3",
|
|
32
|
+
"@tramvai/experiments": "1.82.3"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@tinkoff/utils": "^2.1.2",
|
|
36
|
-
"@tramvai/cli": "1.82.
|
|
37
|
-
"@tramvai/core": "1.82.
|
|
38
|
-
"@tramvai/module-log": "1.82.
|
|
39
|
-
"@tramvai/module-server": "1.82.
|
|
40
|
-
"@tramvai/papi": "1.82.
|
|
41
|
-
"@tramvai/state": "1.82.
|
|
42
|
-
"@tramvai/test-helpers": "1.82.
|
|
43
|
-
"@tramvai/test-mocks": "1.82.
|
|
44
|
-
"@tramvai/tokens-common": "1.82.
|
|
36
|
+
"@tramvai/cli": "1.82.3",
|
|
37
|
+
"@tramvai/core": "1.82.3",
|
|
38
|
+
"@tramvai/module-log": "1.82.3",
|
|
39
|
+
"@tramvai/module-server": "1.82.3",
|
|
40
|
+
"@tramvai/papi": "1.82.3",
|
|
41
|
+
"@tramvai/state": "1.82.3",
|
|
42
|
+
"@tramvai/test-helpers": "1.82.3",
|
|
43
|
+
"@tramvai/test-mocks": "1.82.3",
|
|
44
|
+
"@tramvai/tokens-common": "1.82.3",
|
|
45
45
|
"@tinkoff/dippy": "0.7.39",
|
|
46
46
|
"react": "*",
|
|
47
47
|
"tslib": "^2.0.3"
|