Skip to content

Commit

Permalink
🆙 update: show the error at storybook/vue
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Jun 17, 2017
1 parent 1e91907 commit 838730f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 60 deletions.
54 changes: 54 additions & 0 deletions app/vue/src/client/preview/ErrorDisplay.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<div class="main">
<div class="heading">{{ message }}</div>
<pre class="code">
<code>
{{ stack }}
</code>
</pre>
</div>
</template>

<script>
export default {
name: 'error-display',
props: {
message: {
type: String,
required: true
},
stack: {
type: String,
required: true
}
}
}
</script>

<style>
.main {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 20;
background-color: rgb(187, 49, 49);
color: #FFF;
webkit-font-smoothing: antialiased;
}
.heading {
font-size: 20;
font-weight: 600;
letter-spacing: 0.2;
margin: 10px 0;
font-family: -apple-system, ".SFNSText-Regular", "San Francisco", Roboto, "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
}
.code {
font-size: 14;
width: 100vw;
overflow: auto;
}
</style>
50 changes: 0 additions & 50 deletions app/vue/src/client/preview/error_display.js

This file was deleted.

27 changes: 17 additions & 10 deletions app/vue/src/client/preview/render.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Vue from 'vue';
import ErrorDisplay from './ErrorDisplay.vue';

import { window } from 'global';
// import { stripIndents } from 'common-tags';
// import ErrorDisplay from './error_display';

// check whether we're running on node/browser
const isBrowser = typeof window !== 'undefined';
Expand All @@ -12,22 +12,29 @@ const logger = console;
let previousKind = '';
let previousStory = '';
let app = null;
let err = null;

export function renderError(error) {
const properError = new Error(error.title);
properError.stack = error.description;
function renderErrorDisplay(error) {
if (err) err.$destroy();

// const redBox = <ErrorDisplay error={properError} />;
// ReactDOM.render(redBox, rootEl);
err = new Vue({
el: '#error-display',
render(h) {
return h('div', { attrs: { id: 'error-display' } }, [
h(ErrorDisplay, { props: { message: error.message, stack: error.stack } })
]);
},
});
}

export function renderError(error) {
renderErrorDisplay(error);
}

export function renderException(error) {
// We always need to render redbox in the mainPage if we get an error.
// Since this is an error, this affects to the main page as well.
const realError = new Error(error.message);
realError.stack = error.stack;
// const redBox = <ErrorDisplay error={realError} />;
// ReactDOM.render(redBox, rootEl);
renderErrorDisplay(error);

// Log the stack to the console. So, user could check the source code.
logger.error(error.stack);
Expand Down

0 comments on commit 838730f

Please sign in to comment.