Skip to content

Commit a2dcc94

Browse files
committed
improving error handling in main
1 parent 48584a8 commit a2dcc94

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/main.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ module.exports = function (public_key, config) {
9191
}
9292

9393
if (config.url_root === undefined) {
94-
config.url_root = '/'
94+
config.url_root = window.location.pathname
9595
} else if (!config.url_root.startsWith('/')) {
96-
config.url_root = '/'
96+
config.url_root = window.location.pathname
9797
error = 'the "url_root" config parameter should start (and probably end) with a slash "/"'
9898
}
9999

@@ -104,12 +104,17 @@ module.exports = function (public_key, config) {
104104
config.router_mode = 'hash'
105105
}
106106

107+
if (config.console === undefined) {
108+
config.console = console
109+
}
110+
107111
if (config.element === undefined) {
108112
config.element = '#socket'
109113
}
110114

111-
if (config.console === undefined) {
112-
config.console = console
115+
if (document.querySelector(config.element) === null) {
116+
config.console.error(`SOCKET: page element "${config.element}" does not exist, unable to start socket view.`)
117+
return
113118
}
114119

115120
for (let k of Object.keys(STRINGS)) {
@@ -134,17 +139,21 @@ module.exports = function (public_key, config) {
134139
components: {
135140
app
136141
},
142+
created: function () {
143+
if (error !== null) {
144+
this.handle_error(error)
145+
}
146+
},
137147
methods: {
138148
// get_data is called by components, eg. grid
139149
handle_error: function (error_message) {
140150
this.error = error_message || 'unknown'
141-
config.console.error(this.error)
151+
config.console.error('SOCKET: ' + this.error)
142152
Raven.captureException(new Error(this.error))
143153
},
144154
get_list: function () {
145155
// if an error already exists show that and return
146156
if (error !== null) {
147-
this.handle_error(error)
148157
return
149158
}
150159
let xhr = new window.XMLHttpRequest()

0 commit comments

Comments
 (0)