Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions functions/helloworld/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,47 +120,68 @@ exports.helloGCSGeneric = (event, callback) => {
};
// [END functions_helloworld_storage_generic]

// [START functions_helloworld_error]
/**
* Background Cloud Function that throws an error.
*
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/

exports.helloError = (event, callback) => {
// This WILL be reported to Stackdriver errors
throw new Error('I failed you');
// [START functions_helloworld_error]
// These WILL be reported to Stackdriver errors
console.error(new Error('I failed you'));
throw new Error('I failed you'); // Will cause a cold start if not caught

// [END functions_helloworld_error]
};
// [END functions_helloworld_error]

/* eslint-disable */
// [START functions_helloworld_error_2]
/**
* Background Cloud Function that throws a value.
*
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
/* eslint-disable no-throw-literal */

exports.helloError2 = (event, callback) => {
// This will NOT be reported to Stackdriver errors
throw 1;
// [START functions_helloworld_error]
// These will NOT be reported to Stackdriver errors
console.info(new Error('I failed you')); // Logging an Error object at the info level
console.error('I failed you'); // Logging something other than an Error object
throw 1; // Throwing something other than an Error object
// [END functions_helloworld_error]
};
// [END functions_helloworld_error_2]
/* eslint-enable no-throw-literal */

// [START functions_helloworld_error_3]
/**
* Background Cloud Function that throws an error.
* Background Cloud Function that returns an error.
*
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
/* eslint-disable */
exports.helloError3 = (event, callback) => {
// This will NOT be reported to Stackdriver errors
// [START functions_helloworld_error]
callback('I failed you');
// [END functions_helloworld_error]
};
// [END functions_helloworld_error_3]
/* eslint-enable */

/**
* HTTP Cloud Function that returns an error.
*
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloError4 = (req, res) => {
// This will NOT be reported to Stackdriver errors
// [START functions_helloworld_error]
res.status(500).send('I failed you');
// [END functions_helloworld_error]
};

// [START functions_helloworld_template]
const path = require('path');
const pug = require('pug');
Expand Down
10 changes: 6 additions & 4 deletions functions/tips/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ exports.avoidInfiniteRetries = (event, callback) => {
};
// [END functions_tips_infinite_retries]

// [START functions_tips_retry_promise]
// [START functions_tips_retry]
/**
* Background Cloud Function that demonstrates
* how to toggle retries using a promise
Expand All @@ -172,15 +172,15 @@ exports.avoidInfiniteRetries = (event, callback) => {
exports.retryPromise = (event) => {
const tryAgain = !!event.data.retry;

// [START functions_tips_retry_promise]
if (tryAgain) {
throw new Error(`Retrying...`);
} else {
return Promise.reject(new Error('Not retrying...'));
}
// [END functions_tips_retry_promise]
};
// [END functions_tips_retry_promise]

// [START functions_tips_retry_callback]
/**
* Background Cloud Function that demonstrates
* how to toggle retries using a callback
Expand All @@ -194,15 +194,17 @@ exports.retryCallback = (event, callback) => {
const tryAgain = !!event.data.retry;
const err = new Error('Error!');

// [START functions_tips_retry_callback]
if (tryAgain) {
console.error('Retrying:', err);
callback(err);
} else {
console.error('Not retrying:', err);
callback();
}
// [END functions_tips_retry_callback]
};
// [END functions_tips_retry_callback]
// [END functions_tips_retry]

// [START functions_tips_gcp_apis]
const Pubsub = require('@google-cloud/pubsub');
Expand Down