Skip to content

Commit

Permalink
add error page for when something goes wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
jozsefsallai committed Sep 20, 2019
1 parent dc606b2 commit 92ce84a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 18 deletions.
30 changes: 30 additions & 0 deletions src/ErrorPage.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<svelte:head>
<title>Uh-oh!</title>
</svelte:head>

<div class="error-page">
<h1>Uh-oh!</h1>
<p>
It looks like it's not possible to retrieve the contents of the API documentation
at the moment. If you're the owner of this site, make sure that your
<a href={window.INSOMNIA_URL} target="_blank">Insomnia JSON file</a> is accessible.
</p>
<p>
The developer console of your browser might have more things to say about this error.
</p>
</div>

<style>
.error-page {
width: 760px;
margin: 0 auto;
margin-top: 60px;
}
@media only screen and ( max-width: 760px ) {
.error-page {
width: auto;
padding: 15px;
}
}
</style>
45 changes: 27 additions & 18 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import App from './App.svelte';
import ErrorPage from './ErrorPage.svelte';
import CuteConfig from './lib/cuteConfig';

async function app() {
Expand All @@ -11,24 +12,32 @@ async function app() {

window.INSOMNIA_URL = url;

// eslint-disable-next-line no-undef
const json = await fetch(url, {
method: 'GET',
credentials: 'same-origin',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
}).then(res => res.json());

const insomniaConfig = new CuteConfig(json).generate();

return new App({
target: root,
props: {
config: insomniaConfig
}
});
try {
// eslint-disable-next-line no-undef
const json = await fetch(url, {
method: 'GET',
credentials: 'same-origin',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
}).then(res => res.json());

const insomniaConfig = new CuteConfig(json).generate();

return new App({
target: root,
props: {
config: insomniaConfig
}
});
} catch (err) {
console.error(err);

return new ErrorPage({
target: root
});
}
}

export default app();

0 comments on commit 92ce84a

Please sign in to comment.