Skip to content

Commit 129baea

Browse files
authoredMay 24, 2020
feat: add ErrorBox showing full error details (#4)
1 parent 7b2a97f commit 129baea

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎src/components/App.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { initialValues } from '../constants';
1010
import { useAppContext } from './Context';
1111
import HtmlPreview from './HtmlPreview';
1212
import state from '../lib/state';
13+
import ErrorBox from './ErrorBox';
1314

1415
const savedState = state.load();
1516

@@ -60,11 +61,17 @@ function App() {
6061
/>
6162
<div className="output">
6263
<span className="text-blue-600">&gt; </span>
63-
{parsed.text || parsed.error || 'undefined'}
64+
{parsed.error
65+
? `Error: ${parsed.error}`
66+
: parsed.text || 'undefined'}
6467
</div>
6568
</div>
6669

67-
<ElementInfo />
70+
{parsed.error ? (
71+
<ErrorBox caption={parsed.error} body={parsed.errorBody} />
72+
) : (
73+
<ElementInfo />
74+
)}
6875
</div>
6976
</div>
7077

‎src/components/ErrorBox.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
function ErrorBox({ caption, body }) {
4+
return (
5+
<div className="bg-red-600 text-white p-4 rounded space-y-2 font-mono text-xs">
6+
<div className="font-bold text-xs">Error: {caption}</div>
7+
8+
<div className="font-mono text-xs whitespace-pre-wrap">{body}</div>
9+
</div>
10+
);
11+
}
12+
13+
export default ErrorBox;

0 commit comments

Comments
 (0)
Please sign in to comment.