Skip to content

Commit 1328e5c

Browse files
committed
better error display
1 parent aa88bb9 commit 1328e5c

File tree

5 files changed

+80
-52
lines changed

5 files changed

+80
-52
lines changed

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<main>
2323
<div id="socket1"></div>
2424
<div id="socket2"></div>
25+
<div id="socket3"></div>
2526
</main>
2627
</body>
2728
<script>
@@ -30,6 +31,10 @@
3031
})
3132
socket('f8d88b6562b3434ba4ef', {
3233
element: '#socket2',
34+
mode: 'enquiry',
35+
})
36+
socket('f8d88b6562b3434ba4ef', {
37+
element: '#socket3',
3338
mode: 'enquiry-modal',
3439
})
3540
</script>

src/app.vue

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
11
<template>
22
<div id="tcs-app">
3-
<div v-if="$root.error" class="tcs-errors">
4-
<h2>Error</h2>
5-
<p>
6-
An error occurred with TutorCruncher socket:
7-
</p>
8-
<p class="tcs-error-content">{{ $root.error }}</p>
9-
<p>
10-
<dl>
11-
<dt>If you're visiting this site:</dt>
12-
<dd>
13-
Get in touch with the owners of the site and let them know their TutorCruncher socket plugin isn't working.
14-
</dd>
15-
16-
<dt>If you're developing this site:</dt>
17-
<dd>
18-
You might get more information from the developer console, if you can't work out what's wrong contact
19-
20-
</dd>
21-
</dl>
22-
<img src="./assets/error.svg">
23-
</div>
24-
<div v-else>
25-
<router-view></router-view>
26-
</div>
3+
<error v-if="$root.error"></error>
4+
<router-view></router-view>
275
</div>
286
</template>
297

308
<script>
31-
export default {}
32-
</script>
9+
import error from './components/error.vue'
3310
34-
<style lang="scss" scoped>
35-
@import './conf';
36-
.tcs-errors {
37-
background-color: $brand-colour;
38-
color: white;
39-
margin: 10px;
40-
padding: 20px 30px;
41-
img {
42-
width: 100%;
43-
}
44-
.tcs-error-content {
45-
font-family: monospace;
46-
background-color: darken($brand-colour, 5%);
47-
padding: 20px 10px;
48-
white-space: pre-wrap;
49-
}
50-
dt {
51-
margin: 15px 0 5px;
52-
font-weight: 500;
53-
}
11+
export default {
12+
components: {error}
5413
}
55-
</style>
14+
</script>

src/components/error.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<div class="tcs-errors">
3+
<h2>Error</h2>
4+
<p>
5+
An error occurred with TutorCruncher socket:
6+
</p>
7+
<p class="tcs-error-content">{{ $root.error }}</p>
8+
<p>
9+
<dl>
10+
<dt>If you're visiting this site:</dt>
11+
<dd>
12+
Get in touch with the owners of the site and let them know their TutorCruncher socket plugin isn't working.
13+
</dd>
14+
15+
<dt>If you're developing this site:</dt>
16+
<dd>
17+
You might get more information from the developer console, if you can't work out what's wrong contact
18+
19+
</dd>
20+
</dl>
21+
<img src="../assets/error.svg">
22+
</div>
23+
</template>
24+
25+
<script>
26+
export default {}
27+
</script>
28+
29+
<style lang="scss">
30+
@import '../conf';
31+
.tcs-errors {
32+
background-color: $brand-colour;
33+
color: white;
34+
margin: 10px;
35+
padding: 20px 30px;
36+
img {
37+
width: 100%;
38+
}
39+
.tcs-error-content {
40+
font-family: monospace;
41+
background-color: darken($brand-colour, 5%);
42+
padding: 20px 10px;
43+
white-space: pre-wrap;
44+
}
45+
dt {
46+
margin: 15px 0 5px;
47+
font-weight: 500;
48+
}
49+
}
50+
</style>

src/components/modal.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
</router-link>
1818
</div>
1919

20-
<slot>
20+
<error v-if="$root.error"></error>
21+
<slot v-else>
2122
Modal content.
2223
</slot>
2324

@@ -29,6 +30,7 @@
2930

3031
<script>
3132
import footer from './footer.vue'
33+
import error from './error.vue'
3234
3335
export default {
3436
methods: {
@@ -37,7 +39,8 @@ export default {
3739
},
3840
},
3941
components: {
40-
'tcs-footer': footer
42+
'tcs-footer': footer,
43+
'error': error,
4144
},
4245
props: {
4346
title: String,

src/main.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import con_modal from './components/con-modal'
1111
import {to_markdown, clean, auto_url_root} from './utils'
1212

1313
let dsn = process.env.NODE_ENV === 'production' && 'https://[email protected]/128441'
14-
Raven.config(dsn, {release: process.env.RELEASE}).addPlugin(RavenVue, Vue).install()
14+
let raven_config = {
15+
release: process.env.RELEASE,
16+
tags: {
17+
host: window.location.host,
18+
}
19+
}
20+
Raven.config(dsn, raven_config).addPlugin(RavenVue, Vue).install()
1521

1622
Vue.use(VueRouter)
1723

@@ -126,6 +132,7 @@ module.exports = function (public_key, config) {
126132
config[k] = STRINGS[k]
127133
}
128134
}
135+
Raven.setUserContext(config)
129136

130137
return new Vue({
131138
el: config.element,
@@ -199,7 +206,7 @@ response text: "${xhr.responseText}"`)
199206
xhr.open('GET', url)
200207
xhr.onload = () => {
201208
if (xhr.status !== 200) {
202-
throw new Error(`bad response ${xhr.status} at "${url}"`)
209+
this.handle_error(`bad response ${xhr.status} at "${url}"`)
203210
} else {
204211
let con = JSON.parse(xhr.responseText)
205212
Vue.set(this.contractors_extra, link, con)
@@ -217,7 +224,11 @@ response text: "${xhr.responseText}"`)
217224
xhr.open('GET', url)
218225
xhr.onload = () => {
219226
if (xhr.status !== 200) {
220-
throw new Error(`bad response ${xhr.status} at "${url}"`)
227+
this.handle_error(`\
228+
Connection error
229+
requested url: "${url}"
230+
response status: ${xhr.status}
231+
response text: "${xhr.responseText}"`)
221232
} else {
222233
this.enquiry_form_info = Object.assign({}, this.enquiry_form_info, JSON.parse(xhr.responseText))
223234
}

0 commit comments

Comments
 (0)