Skip to content

Commit e79ee37

Browse files
author
Ace Nassri
authored
Adjust retry error region-tags for docs migration (#615)
* Adjust retry error tags * Unify hello-world error region-tags * Further error sample unification * Clarify comments + add HTTP sample * Move region tags inside functions * Fix typo * s/Errors/Error Reporting/
1 parent 1b5e746 commit e79ee37

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

functions/helloworld/index.js

+34-13
Original file line numberDiff line numberDiff line change
@@ -125,47 +125,68 @@ exports.helloGCSGeneric = (event, callback) => {
125125
};
126126
// [END functions_helloworld_storage_generic]
127127

128-
// [START functions_helloworld_error]
129128
/**
130129
* Background Cloud Function that throws an error.
131130
*
132131
* @param {object} event The Cloud Functions event.
133132
* @param {function} callback The callback function.
134133
*/
134+
135135
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]
138142
};
139-
// [END functions_helloworld_error]
140143

141-
/* eslint-disable */
142-
// [START functions_helloworld_error_2]
143144
/**
144145
* Background Cloud Function that throws a value.
145146
*
146147
* @param {object} event The Cloud Functions event.
147148
* @param {function} callback The callback function.
148149
*/
150+
/* eslint-disable no-throw-literal */
151+
149152
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]
152159
};
153-
// [END functions_helloworld_error_2]
160+
/* eslint-enable no-throw-literal */
154161

155-
// [START functions_helloworld_error_3]
156162
/**
157-
* Background Cloud Function that throws an error.
163+
* Background Cloud Function that returns an error.
158164
*
159165
* @param {object} event The Cloud Functions event.
160166
* @param {function} callback The callback function.
161167
*/
168+
/* eslint-disable */
162169
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]
164172
callback('I failed you');
173+
// [END functions_helloworld_error]
165174
};
166-
// [END functions_helloworld_error_3]
167175
/* eslint-enable */
168176

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+
169190
// [START functions_helloworld_template]
170191
const path = require('path');
171192
const pug = require('pug');

0 commit comments

Comments
 (0)