@@ -15,12 +15,12 @@ const ConfiguredVueRouter = config => new VueRouter({
1515 mode : config . router_mode ,
1616 routes : [
1717 {
18- path : '/' ,
18+ path : config . url_root ,
1919 name : 'index' ,
2020 component : grid ,
2121 children : [
2222 {
23- path : '/ :link',
23+ path : config . url_root + ' :link',
2424 name : 'modal' ,
2525 component : modal ,
2626 }
@@ -31,19 +31,27 @@ const ConfiguredVueRouter = config => new VueRouter({
3131
3232module . exports = function ( public_key , config ) {
3333 config = config || { }
34+ let error = null
3435
3536 if ( config . api_root === undefined ) {
3637 config . api_root = process . env . SOCKET_API_URL
3738 }
3839
39- if ( config . element === undefined ) {
40- config . element = '#socket'
40+ if ( config . url_root === undefined ) {
41+ config . url_root = '/'
42+ } else if ( ! config . url_root . startsWith ( '/' ) ) {
43+ config . url_root = '/'
44+ error = 'the "url_root" config parameter should start (and probably end) with a slash "/"'
4145 }
4246
4347 if ( config . router_mode === undefined ) {
4448 config . router_mode = 'hash'
4549 }
4650
51+ if ( config . element === undefined ) {
52+ config . element = '#socket'
53+ }
54+
4755 if ( config . contact_html === undefined ) {
4856 config . contact_html = 'To request tutoring from {name} please <a href="{contact_link}">get in touch</a> with us.'
4957 }
@@ -72,7 +80,17 @@ module.exports = function (public_key, config) {
7280 } ,
7381 methods : {
7482 // get_data is called by components, eg. grid
83+ handle_error : function ( error_message ) {
84+ this . error = error_message || 'unknown'
85+ console . error ( this . error )
86+ Raven . captureException ( new Error ( this . error ) )
87+ } ,
7588 get_list : function ( ) {
89+ // if an error already exists show that and return
90+ if ( error !== null ) {
91+ this . handle_error ( error )
92+ return
93+ }
7694 let xhr = new window . XMLHttpRequest ( )
7795 let url = `${ config . api_root } /${ public_key } /contractors`
7896 xhr . open ( 'GET' , url )
@@ -87,22 +105,20 @@ module.exports = function (public_key, config) {
87105 this . contractors . splice ( 0 )
88106 contractors . forEach ( con => this . contractors . push ( con ) )
89107 } catch ( e ) {
90- this . error = `\
108+ this . handle_error ( `\
91109${ e . toString ( ) }
92110requested url: "${ url } "
93111response status: ${ xhr . status }
94112response text:
95- ${ xhr . responseText } `
96- Raven . captureException ( new Error ( this . error ) )
113+ ${ xhr . responseText } `)
97114 }
98115 }
99116 xhr . onerror = ( ) => {
100- this . error = `\
117+ this . handle_error ( `\
101118Connection error
102119requested url: "${ url } "
103120response status: ${ xhr . status }
104- response text: "${ xhr . responseText } "`
105- Raven . captureException ( new Error ( this . error ) )
121+ response text: "${ xhr . responseText } "` )
106122 }
107123 xhr . send ( )
108124 } ,
0 commit comments