Skip to content

Commit f985f23

Browse files
authored
Show actual errors in sandbox error (codesandbox#3900)
* show actual errors * reset to false * clean state * ts
1 parent f34790d commit f985f23

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
168168
}
169169

170170
state.editor.isLoading = !hasExistingSandbox;
171-
state.editor.notFound = false;
172171

173172
const url = new URL(document.location.href);
174173
const invitationToken = url.searchParams.get('ts');
@@ -212,13 +211,25 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
212211
actions.internal.setCurrentSandbox(sandbox);
213212
actions.workspace.openDefaultItem();
214213
} catch (error) {
215-
state.editor.notFound = true;
216-
let detail = error.response?.data?.errors?.detail;
214+
const data = error.response?.data;
215+
const errors = data?.errors;
216+
let detail = errors?.detail;
217+
217218
if (Array.isArray(detail)) {
218219
detail = detail[0];
220+
} else if (typeof errors === 'object') {
221+
detail = errors[Object.keys(errors)[0]];
222+
} else if (data?.error) {
223+
detail = data?.error;
219224
}
220-
state.editor.error = detail || error.message;
225+
226+
state.editor.error = {
227+
message: detail || error.message,
228+
status: error.response.status,
229+
};
230+
221231
state.editor.isLoading = false;
232+
222233
return;
223234
}
224235

packages/app/src/app/overmind/namespaces/editor/state.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ type State = {
4343
// EditorPreview is using it... weird stuff
4444
devToolTabs: Derive<State, ViewConfig[]>;
4545
isLoading: boolean;
46-
notFound: boolean;
47-
error: string | null;
46+
error: {
47+
status: number;
48+
message: string;
49+
} | null;
4850
isResizing: boolean;
4951
changedModuleShortids: Derive<State, string[]>;
5052
currentTabId: string | null;
@@ -85,7 +87,6 @@ export const state: State = {
8587
currentModuleShortid: null,
8688
mainModuleShortid: null,
8789
isLoading: true,
88-
notFound: false,
8990
error: null,
9091
isResizing: false,
9192
modulesByPath: {},

packages/app/src/app/pages/Sandbox/index.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Title } from 'app/components/Title';
77
import { useOvermind } from 'app/overmind';
88
import { GithubIntegration } from 'app/pages/common/GithubIntegration';
99
import { Navigation } from 'app/pages/common/Navigation';
10-
import { NotFound } from 'app/pages/common/NotFound';
1110
import React, { useEffect } from 'react';
1211
import { Helmet } from 'react-helmet';
1312
import { Link } from 'react-router-dom';
@@ -52,9 +51,13 @@ export const Sandbox = React.memo<Props>(
5251
);
5352

5453
function getContent() {
55-
const { hasLogIn, isLoggedIn } = state;
54+
const {
55+
hasLogIn,
56+
isLoggedIn,
57+
editor: { error },
58+
} = state;
5659

57-
if (state.editor.error) {
60+
if (error) {
5861
const isGithub = match.params.id.includes('github');
5962

6063
return (
@@ -70,7 +73,7 @@ export const Sandbox = React.memo<Props>(
7073
Something went wrong
7174
</div>
7275
<Title style={{ fontSize: '1.25rem', marginBottom: 0 }}>
73-
{state.editor.error}
76+
{error.message}
7477
</Title>
7578
<br />
7679
<div style={{ display: 'flex', maxWidth: 400, width: '100%' }}>
@@ -81,7 +84,7 @@ export const Sandbox = React.memo<Props>(
8184
{hasLogIn ? 'Dashboard' : 'Homepage'}
8285
</Button>
8386
</div>
84-
{isLoggedIn && isGithub && (
87+
{isLoggedIn && isGithub && error.status !== 422 && (
8588
<div
8689
style={{ maxWidth: 400, marginTop: '2.5rem', width: '100%' }}
8790
>
@@ -127,10 +130,6 @@ export const Sandbox = React.memo<Props>(
127130
);
128131
}
129132

130-
if (state.editor.notFound) {
131-
return <NotFound />;
132-
}
133-
134133
return null;
135134
}
136135

0 commit comments

Comments
 (0)