@shuvi/platform-web 1.0.21 → 1.0.23

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.
@@ -13,7 +13,6 @@ import application from '@shuvi/platform-shared/shuvi-app/application';
13
13
  import { createRouter, createBrowserHistory, createHashHistory } from '@shuvi/router';
14
14
  import { historyMode } from '@shuvi/app/files/routerConfig';
15
15
  import { SHUVI_ERROR } from '@shuvi/shared/constants';
16
- import { serializeServerError } from '../helper/serializeServerError';
17
16
  import isThirdSite from '../helper/isThirdSite';
18
17
  let app;
19
18
  export const createApp = ({ routes, appData, appComponent }) => {
@@ -114,15 +113,22 @@ export const createApp = ({ routes, appData, appComponent }) => {
114
113
  return;
115
114
  }
116
115
  if (isResponse(error) && error.status >= 400 && error.status < 600) {
116
+ // client error has no status code
117
117
  app.setError({
118
- code: error.status,
119
118
  message: error.data
120
119
  });
121
120
  next();
122
121
  return;
123
122
  }
124
- app.setError(serializeServerError(error));
125
- next();
123
+ // If loader throws a error, we need to rethrow it
124
+ app.setError({
125
+ message: SHUVI_ERROR.CLIENT_ERROR.message,
126
+ error
127
+ });
128
+ // to trigger error-overlay at dev
129
+ next(() => {
130
+ throw error;
131
+ });
126
132
  return;
127
133
  }
128
134
  next(() => {
@@ -1,12 +1,16 @@
1
1
  // @ts-ignore
2
2
  import stripAnsi from 'strip-ansi';
3
+ import { SHUVI_ERROR } from '@shuvi/shared/constants';
3
4
  function errorToJSON(err) {
4
5
  return {
5
6
  code: 500,
6
7
  message: stripAnsi(err.message),
7
- name: err.name,
8
8
  source: 'server',
9
- stack: err.stack
9
+ error: {
10
+ name: err.name,
11
+ stack: err.stack,
12
+ message: err.message
13
+ }
10
14
  };
11
15
  }
12
16
  export function serializeServerError(err) {
@@ -15,7 +19,6 @@ export function serializeServerError(err) {
15
19
  }
16
20
  return {
17
21
  code: 500,
18
- message: 'Internal Server Error',
19
- name: 'Internal Server Error'
22
+ message: SHUVI_ERROR.SERVER_ERROR.message
20
23
  };
21
24
  }
@@ -5,10 +5,10 @@ import ErrorPage from './ErrorPage';
5
5
  import { ErrorBoundary } from './ErrorBoundary';
6
6
  import { Provider, useSharedModel } from './store';
7
7
  function ErrorGuard({ children = null }) {
8
- var _a, _b;
9
8
  const errorState = useSharedModel(errorModelName, errorModel);
10
- if (errorState.hasError) {
11
- return (<ErrorPage code={(_a = errorState.error) === null || _a === void 0 ? void 0 : _a.code} message={(_b = errorState.error) === null || _b === void 0 ? void 0 : _b.message}/>);
9
+ const { error, hasError } = errorState;
10
+ if (hasError) {
11
+ return (<ErrorPage code={error === null || error === void 0 ? void 0 : error.code} message={error === null || error === void 0 ? void 0 : error.message} error={error === null || error === void 0 ? void 0 : error.error}/>);
12
12
  }
13
13
  return <>{children}</>;
14
14
  }
@@ -2,4 +2,5 @@
2
2
  export default function Error({ errorCode, errorDesc }: {
3
3
  errorCode?: number;
4
4
  errorDesc?: string;
5
+ error?: Error;
5
6
  }): JSX.Element;
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import { Head } from './head';
3
- import { useApp } from './ApplicationContext';
4
3
  const style = {
5
4
  container: {
6
5
  color: '#000',
@@ -15,26 +14,24 @@ const style = {
15
14
  error: { display: 'flex', alignItems: 'center', justifyContent: 'center' },
16
15
  errorCode: {
17
16
  fontSize: '24px',
18
- fontWeight: 500
17
+ fontWeight: 500,
18
+ borderRight: '1px solid rgba(0, 0, 0, 0.3)',
19
+ paddingRight: '20px',
20
+ marginRight: '20px'
19
21
  },
20
22
  errorDesc: {
21
23
  fontSize: '16px',
22
- lineHeight: '1',
23
- borderLeft: '1px solid rgba(0, 0, 0, 0.3)',
24
- paddingLeft: '20px',
25
- marginLeft: '20px'
24
+ lineHeight: '1'
26
25
  }
27
26
  };
28
27
  export default function Error({ errorCode, errorDesc }) {
29
- const app = useApp();
30
28
  return (<div style={style.container}>
31
29
  <Head>
32
30
  <title>Page Error</title>
33
31
  </Head>
34
32
 
35
33
  <div style={style.error}>
36
- {/* 500 will cause confusion for SPA application, so only show error code on SSR */}
37
- {app.config.ssr && <div style={style.errorCode}>{errorCode}</div>}
34
+ {errorCode !== undefined && (<div style={style.errorCode}>{errorCode}</div>)}
38
35
  <div style={style.errorDesc}>{errorDesc || 'Error'}</div>
39
36
  </div>
40
37
  </div>);
@@ -19,7 +19,7 @@ class ErrorBoundary extends React.PureComponent {
19
19
  render() {
20
20
  return this.state.error ? (
21
21
  // The component has to be unmounted or else it would continue to error
22
- <ErrorPage code={SHUVI_ERROR.APP_ERROR.code} message={SHUVI_ERROR.APP_ERROR.message}/>) : this.props.children;
22
+ <ErrorPage message={SHUVI_ERROR.CLIENT_ERROR.message} error={this.state.error}/>) : this.props.children;
23
23
  }
24
24
  }
25
25
  export { ErrorBoundary };
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
- export default function ErrorPage({ code, message }: {
2
+ export default function ErrorPage({ code, message, error }: {
3
3
  code?: number;
4
4
  message?: string;
5
+ error?: Error;
5
6
  }): JSX.Element;
@@ -2,6 +2,6 @@ import * as React from 'react';
2
2
  import error from './Error';
3
3
  import userError from '@shuvi/app/user/error';
4
4
  const Error = userError || error;
5
- export default function ErrorPage({ code, message }) {
6
- return <Error errorCode={code} errorDesc={message}/>;
5
+ export default function ErrorPage({ code, message, error }) {
6
+ return <Error errorCode={code} errorDesc={message} error={error}/>;
7
7
  }
@@ -29,7 +29,7 @@ export class ReactClientView {
29
29
  const { getServerError } = require('@shuvi/error-overlay');
30
30
  if (appError && appError.source === 'server') {
31
31
  setTimeout(() => {
32
- var _a;
32
+ var _a, _b, _c;
33
33
  let error;
34
34
  try {
35
35
  // Generate a new error object. We `throw` it because some browsers
@@ -40,8 +40,8 @@ export class ReactClientView {
40
40
  catch (e) {
41
41
  error = e;
42
42
  }
43
- error.name = (_a = appError.name) !== null && _a !== void 0 ? _a : '';
44
- error.stack = appError.stack;
43
+ error.name = (_b = (_a = appError.error) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
44
+ error.stack = (_c = appError.error) === null || _c === void 0 ? void 0 : _c.stack;
45
45
  throw getServerError(error);
46
46
  });
47
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-web",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -72,18 +72,18 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@next/react-refresh-utils": "12.1.6",
75
- "@shuvi/error-overlay": "1.0.21",
76
- "@shuvi/hook": "1.0.21",
77
- "@shuvi/platform-shared": "1.0.21",
78
- "@shuvi/router": "1.0.21",
79
- "@shuvi/router-react": "1.0.21",
80
- "@shuvi/runtime": "1.0.21",
81
- "@shuvi/shared": "1.0.21",
82
- "@shuvi/toolpack": "1.0.21",
83
- "@shuvi/utils": "1.0.21",
75
+ "@shuvi/error-overlay": "1.0.23",
76
+ "@shuvi/hook": "1.0.23",
77
+ "@shuvi/platform-shared": "1.0.23",
78
+ "@shuvi/router": "1.0.23",
79
+ "@shuvi/router-react": "1.0.23",
80
+ "@shuvi/runtime": "1.0.23",
81
+ "@shuvi/shared": "1.0.23",
82
+ "@shuvi/toolpack": "1.0.23",
83
+ "@shuvi/utils": "1.0.23",
84
84
  "content-type": "1.0.4",
85
85
  "core-js": "3.6.5",
86
- "doura": "0.0.9",
86
+ "doura": "0.0.11",
87
87
  "ejs": "3.1.5",
88
88
  "fs-extra": "9.0.1",
89
89
  "node-mocks-http": "1.11.0",
@@ -91,14 +91,14 @@
91
91
  "raw-body": "2.4.1",
92
92
  "react": "18.2.0",
93
93
  "react-dom": "18.2.0",
94
- "react-doura": "0.0.9",
94
+ "react-doura": "0.0.11",
95
95
  "react-refresh": "0.12.0",
96
96
  "strip-ansi": "6.0.0",
97
97
  "use-sync-external-store": "1.1.0",
98
98
  "whatwg-fetch": "3.0.0"
99
99
  },
100
100
  "peerDependencies": {
101
- "@shuvi/service": "1.0.21"
101
+ "@shuvi/service": "1.0.23"
102
102
  },
103
103
  "devDependencies": {
104
104
  "@shuvi/service": "workspace:*",