Giter VIP home page Giter VIP logo

Comments (4)

JakeChampion avatar JakeChampion commented on May 27, 2024 1

I believe this is because you are catching the error, which implies it has been handled by the application.

if you rethrow the error after you send your responses, Sentry will report them.

'use strict';
const SparkPost = require('sparkpost');
const { decrypt, } = require('../crypto.js');
const RavenLambdaWrapper = require("serverless-sentry-lib");

// Wrap handler for automated error and exception logging
const ravenConfig = {
  captureErrors: true,
  captureUnhandledRejections: true,
  captureMemoryWarnings: true,
  captureTimeoutWarnings: true,
  ravenClient: require("raven") // don't forget!
};

module.exports.index = RavenLambdaWrapper.handler(ravenConfig, (event, context, callback) => {
  context.callbackWaitsForEmptyEventLoop = true;
  const keys = event.requestContext.authorizer;
  const body = JSON.parse(event.body);
  console.log('event', JSON.stringify(body, 3));
  const response = {
    statusCode: 200,
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Credentials': true,
    },
    body: '',
  };

  const client = new SparkPost(keys.SparkPostKey);

  const RECIPIENT = body.RECIPIENT;
  const TEMPLATE_ID = body.TEMPLATE_ID;
  const CAMPAIGN_ID = body.CAMPAIGN_ID;
  const SUBSTITUTION_DATA = body.SUBSTITUTION_DATA;

  try {
    if (SUBSTITUTION_DATA && SUBSTITUTION_DATA.confirmation_link) {
      SUBSTITUTION_DATA.confirmation_link = decrypt(SUBSTITUTION_DATA.confirmation_link);
    }
  } catch (err) {
    console.log('to decryption err', err);
    response.statusCode = 400;
    response.body = JSON.stringify({
      status: 'Failed',
      error: 'Decryption error in \'confirmation_link\'',
    });
    callback(null, response);
    throw err;
  }

  client.transmissions.send({
    options: {
      track_opens: true,
      track_clicks: true,
      transactional: true,
      ip_pool: "trans2"
    },
    campaign_id: CAMPAIGN_ID,
    content: {
      template_id: TEMPLATE_ID
    },
    substitution_data: SUBSTITUTION_DATA,
    recipients: RECIPIENT
  })
    .then(data => {
      console.log("Email has been sent. ", data);
      response.body = JSON.stringify({
        success: true,
        data: data,
      });
      callback(null, response);

    })
    .catch(err => {
      console.log(err);
      response.statusCode = 400;
      response.body = JSON.stringify({
        success: false,
        error: err,
      });
      callback(null, response);
      throw err;
    });

});

from serverless-sentry-plugin.

ManuelFrigerio avatar ManuelFrigerio commented on May 27, 2024

Hi @JakeChampion, I did that but the error still doesn't show up in Sentry.
I'm stuck to the Waiting for events… page...

from serverless-sentry-plugin.

demetrio812 avatar demetrio812 commented on May 27, 2024

Hello, same for me here, using Typescript and the new handler version, I even tried to call Raven.captureMessage("Hello from Lambda!"); without success.

I've setup the release and it work, but it doesn't log any message...how can I debug it?

from serverless-sentry-plugin.

ppanchal97 avatar ppanchal97 commented on May 27, 2024

I believe this is because you are catching the error, which implies it has been handled by the application.

if you rethrow the error after you send your responses, Sentry will report them.

    .catch(err => {
      console.log(err);
      response.statusCode = 400;
      response.body = JSON.stringify({
        success: false,
        error: err,
      });
      callback(null, response);
      throw err;
    });

});

Thank you - I was facing the same issue where sentry would not pick up any errors logged within the lambda - the solution was to throw an error manually in the catch block such as throw err;

from serverless-sentry-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.