@@ -125,47 +125,68 @@ exports.helloGCSGeneric = (event, callback) => {
125
125
} ;
126
126
// [END functions_helloworld_storage_generic]
127
127
128
- // [START functions_helloworld_error]
129
128
/**
130
129
* Background Cloud Function that throws an error.
131
130
*
132
131
* @param {object } event The Cloud Functions event.
133
132
* @param {function } callback The callback function.
134
133
*/
134
+
135
135
exports . helloError = ( event , callback ) => {
136
- // This WILL be reported to Stackdriver Error Reporting
137
- throw new Error ( 'I failed you' ) ;
136
+ // [START functions_helloworld_error]
137
+ // These WILL be reported to Stackdriver Error Reporting
138
+ console . error ( new Error ( 'I failed you' ) ) ;
139
+ throw new Error ( 'I failed you' ) ; // Will cause a cold start if not caught
140
+
141
+ // [END functions_helloworld_error]
138
142
} ;
139
- // [END functions_helloworld_error]
140
143
141
- /* eslint-disable */
142
- // [START functions_helloworld_error_2]
143
144
/**
144
145
* Background Cloud Function that throws a value.
145
146
*
146
147
* @param {object } event The Cloud Functions event.
147
148
* @param {function } callback The callback function.
148
149
*/
150
+ /* eslint-disable no-throw-literal */
151
+
149
152
exports . helloError2 = ( event , callback ) => {
150
- // This will NOT be reported to Stackdriver Error Reporting
151
- throw 1 ;
153
+ // [START functions_helloworld_error]
154
+ // These will NOT be reported to Stackdriver Error Reporting
155
+ console . info ( new Error ( 'I failed you' ) ) ; // Logging an Error object at the info level
156
+ console . error ( 'I failed you' ) ; // Logging something other than an Error object
157
+ throw 1 ; // Throwing something other than an Error object
158
+ // [END functions_helloworld_error]
152
159
} ;
153
- // [END functions_helloworld_error_2]
160
+ /* eslint-enable no-throw-literal */
154
161
155
- // [START functions_helloworld_error_3]
156
162
/**
157
- * Background Cloud Function that throws an error.
163
+ * Background Cloud Function that returns an error.
158
164
*
159
165
* @param {object } event The Cloud Functions event.
160
166
* @param {function } callback The callback function.
161
167
*/
168
+ /* eslint-disable */
162
169
exports . helloError3 = ( event , callback ) => {
163
- // This will NOT be reported to Stackdriver errors
170
+ // This will NOT be reported to Stackdriver Error Reporting
171
+ // [START functions_helloworld_error]
164
172
callback ( 'I failed you' ) ;
173
+ // [END functions_helloworld_error]
165
174
} ;
166
- // [END functions_helloworld_error_3]
167
175
/* eslint-enable */
168
176
177
+ /**
178
+ * HTTP Cloud Function that returns an error.
179
+ *
180
+ * @param {Object } req Cloud Function request context.
181
+ * @param {Object } res Cloud Function response context.
182
+ */
183
+ exports . helloError4 = ( req , res ) => {
184
+ // This will NOT be reported to Stackdriver Error Reporting
185
+ // [START functions_helloworld_error]
186
+ res . status ( 500 ) . send ( 'I failed you' ) ;
187
+ // [END functions_helloworld_error]
188
+ } ;
189
+
169
190
// [START functions_helloworld_template]
170
191
const path = require ( 'path' ) ;
171
192
const pug = require ( 'pug' ) ;
0 commit comments