@@ -33,6 +33,11 @@ Steps.fillStepOutput = function(id, data) {
33
33
$ ( id ) . html ( 'Output: ' + data ) . slideDown ( ) ;
34
34
}
35
35
36
+ Steps . fillStepError = function ( id , errorMsg ) {
37
+ $ ( id ) . html ( errorMsg ) . slideDown ( ) ;
38
+ }
39
+
40
+
36
41
Steps . fillBtn = function ( id , message ) {
37
42
$ ( id ) . addClass ( 'success' ) . html ( '✓ ' + message ) ;
38
43
}
@@ -62,9 +67,12 @@ ParseRequest.postData = function() {
62
67
ParseRequest . getData ( ) ;
63
68
e . preventDefault ( ) ;
64
69
} ) ;
65
- } ) ;
70
+ } ,
71
+ function ( error ) {
72
+ Steps . fillStepError ( '#step-1-error' , 'There was a failure: ' + error ) ;
73
+ } ) ;
66
74
XHR . POST ( '/parse/classes/GameScore' ) ;
67
- }
75
+ } ;
68
76
69
77
ParseRequest . getData = function ( ) {
70
78
XHR . setCallback ( function ( data ) {
@@ -77,10 +85,13 @@ ParseRequest.getData = function() {
77
85
Steps . bindBtn ( '#step-3-btn' , function ( e ) {
78
86
ParseRequest . postCloudCodeData ( ) ;
79
87
e . preventDefault ( ) ;
80
- } )
81
- } ) ;
88
+ } ) ;
89
+ } ,
90
+ function ( error ) {
91
+ Steps . fillStepError ( '#step-2-error' , 'There was a failure: ' + error ) ;
92
+ } ) ;
82
93
XHR . GET ( '/parse/classes/GameScore' ) ;
83
- }
94
+ } ;
84
95
85
96
ParseRequest . postCloudCodeData = function ( ) {
86
97
XHR . setCallback ( function ( data ) {
@@ -90,7 +101,10 @@ ParseRequest.postCloudCodeData = function() {
90
101
Steps . fillBtn ( '#step-3-btn' , 'Tested' ) ;
91
102
// open third step
92
103
Steps . showWorkingMessage ( ) ;
93
- } ) ;
104
+ } ,
105
+ function ( error ) {
106
+ Steps . fillStepError ( '#step-3-error' , 'There was a failure: ' + error ) ;
107
+ } ) ;
94
108
XHR . POST ( '/parse/functions/hello' ) ;
95
109
}
96
110
@@ -120,12 +134,16 @@ Config.getUrl = function() {
120
134
121
135
var XHR = { } ;
122
136
123
- XHR . setCallback = function ( callback ) {
137
+ XHR . setCallback = function ( callback , failureCallback ) {
124
138
this . xhttp = new XMLHttpRequest ( ) ;
125
139
var _self = this ;
126
140
this . xhttp . onreadystatechange = function ( ) {
127
- if ( _self . xhttp . readyState == 4 && _self . xhttp . status >= 200 && _self . xhttp . status <= 299 ) {
128
- callback ( _self . xhttp . responseText ) ;
141
+ if ( _self . xhttp . readyState == 4 ) {
142
+ if ( _self . xhttp . status >= 200 && _self . xhttp . status <= 299 ) {
143
+ callback ( _self . xhttp . responseText ) ;
144
+ } else {
145
+ failureCallback ( _self . xhttp . responseText ) ;
146
+ }
129
147
}
130
148
} ;
131
149
}
0 commit comments