Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function setupImplicit() {
// [START error_reporting_setup_implicit]
// [START error_reporting_setup_nodejs_implicit]
// Imports the Google Cloud client library
const {ErrorReporting} = require('@google-cloud/error-reporting');
// Instantiates a client
const errors = new ErrorReporting();
// Reports a simple error
errors.report('Something broke!');
// [END error_reporting_setup_nodejs_implicit]
// [END error_reporting_setup_implicit]
}
function manual() {
// [START error_reporting_manual]
// [START error_reporting_setup_nodejs_manual]
// Imports the Google Cloud client library
const {ErrorReporting} = require('@google-cloud/error-reporting');
// Instantiates a client
const errors = new ErrorReporting();
// Use the error message builder to customize all fields ...
const errorEvent = errors.event();
// Add error information
errorEvent.setMessage('My error message');
errorEvent.setUser('root@nexus');
// Report the error event
errors.report(errorEvent, () => {
console.log('Done reporting error event!');
});
// Report an Error object
errors.report(new Error('My error message'), () => {
console.log('Done reporting Error object!');
function setupExplicit() {
// [START error_reporting_setup_explicit]
// [START error_reporting_setup_nodejs_explicit]
// Imports the Google Cloud client library
const ErrorReporting = require('@google-cloud/error-reporting')
.ErrorReporting;
// On Node 6+ the following syntax can be used instead:
// const {ErrorReporting} = require('@google-cloud/error-reporting');
// With ES6 style imports via TypeScript or Babel, the following
// syntax can be used instead:
// import {ErrorReporting} from '@google-cloud/error-reporting';
// Instantiates a client
const errors = new ErrorReporting({
projectId: 'your-project-id',
keyFilename: '/path/to/key.json',
});
// Reports a simple error
errors.report('Something broke!');
// [END error_reporting_setup_nodejs_explicit]
// [END error_reporting_setup_explicit]
}
function explicitSetup() {
// [START error_reporting_setup_explicit]
// [START error_reporting_setup_nodejs_explicit]
// Imports the Google Cloud client library
const {ErrorReporting} = require('@google-cloud/error-reporting');
// Instantiates a client
const errors = new ErrorReporting({
projectId: 'your-project-id',
keyFilename: '/path/to/key.json',
});
// Reports a simple error
errors.report('Something broke!');
// [END error_reporting_setup_nodejs_explicit]
// [END error_reporting_setup_explicit]
}
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use strict';
require('@google-cloud/debug-agent').start({ allowExpressions: true });
const ErrorReporting = require(
'@google-cloud/error-reporting').ErrorReporting;
const path = require('path');
const express = require('express');
const config = require('./config');
const errorReporting = new ErrorReporting();
const app = express();
// Static files
app.use(express.static('public/'));
app.disable('etag');
app.set('views', path.join(__dirname, 'web-app/views'));
app.set('view engine', 'pug');
app.set('trust proxy', true);
app.set('json spaces', 2);
// Questions
app.use('/questions', require('./web-app/questions'));
// Quizzes API
app.use('/api/quizzes', require('./api'));
function quickstart() {
// [START error_reporting_quickstart]
// Imports the Google Cloud client library
const {ErrorReporting} = require('@google-cloud/error-reporting');
// Instantiates a client
const errors = new ErrorReporting();
// Reports a simple error
errors.report('Something broke!');
// [END error_reporting_quickstart]
}
quickstart();
// [START error_reporting_setup_nodejs_express]
const express = require('express');
// Imports the Google Cloud client library
const ErrorReporting = require('@google-cloud/error-reporting')
.ErrorReporting;
// On Node 6+ the following syntax can be used instead:
// const {ErrorReporting} = require('@google-cloud/error-reporting');
// With ES6 style imports via TypeScript or Babel, the following
// syntax can be used instead:
// import {ErrorReporting} from '@google-cloud/error-reporting';
// Instantiates a client
const errors = new ErrorReporting();
const app = express();
app.get('/error', (req, res, next) => {
res.send('Something broke!');
next(new Error('Custom error message'));
});
app.get('/exception', () => {
JSON.parse('{"malformedJson": true');
});
// Note that express error handling middleware should be attached after all
// the other routes and use() calls. See the Express.js docs.
app.use(errors.express);
projectId: config.get('GCLOUD_PROJECT')
});
// END TODO
require('@google-cloud/debug-agent').start({
allowExpressions: true,
projectId: config.get('GCLOUD_PROJECT')
});
const path = require('path');
const express = require('express');
const scores = require('./gcp/spanner');
const {ErrorReporting} = require('@google-cloud/error-reporting');
const errorReporting = new ErrorReporting({
projectId: config.get('GCLOUD_PROJECT')
});
const app = express();
// Static files
app.use(express.static('frontend/public/'));
app.disable('etag');
app.set('views', path.join(__dirname, 'web-app/views'));
app.set('view engine', 'pug');
app.set('trust proxy', true);
app.set('json spaces', 2);
// Questions
app.use('/questions', require('./web-app/questions'));