Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send fails with "Response undefined: undefined" #53

Closed
zeevl opened this issue Aug 13, 2021 · 5 comments · Fixed by #55
Closed

send fails with "Response undefined: undefined" #53

zeevl opened this issue Aug 13, 2021 · 5 comments · Fixed by #55

Comments

@zeevl
Copy link

zeevl commented Aug 13, 2021

calling Sendwithus.send is failing every time -- had to downgrade to 4.3.1

Client version

4.3.3

Expected behaviour

email to send

Actual behaviour

Aug 13 12:07:18 lambda  2021-08-13T19:07:16.568Z	29cbee03-d790-4c1d-a976-35d61ef33039	INFO	SENDWITHUS: Built url: https://api.sendwithus.com/api/v1/send 
Aug 13 12:07:18 lambda   2021-08-13T19:07:16.568Z	29cbee03-d790-4c1d-a976-35d61ef33039	INFO	SENDWITHUS: Set headers: {"X-SWU-API-KEY":"----","X-SWU-API-CLIENT":"node-4.3.3"} 
Aug 13 12:07:18 lambda  2021-08-13T19:07:16.902Z	29cbee03-d790-4c1d-a976-35d61ef33039	INFO	SENDWITHUS: Response undefined: undefined 
Aug 13 12:07:18 lambda  2021-08-13T19:07:16.904Z api:apiHandler Error: Request failed with undefined 
Aug 13 12:07:18 lambda  at Sendwithus._handleResponse (/var/task/node_modules/sendwithus/lib/sendwithus.js:110:15) 
Aug 13 12:07:18 lambda  at /var/task/node_modules/sendwithus/lib/sendwithus.js:148:28 
Aug 13 12:07:18 lambda  at processTicksAndRejections (internal/process/task_queues.js:97:5) 
Aug 13 12:07:18 lambda   2021-08-13T19:07:17.180Z	29cbee03-d790-4c1d-a976-35d61ef33039	ERROR	Invoke Error 	{"message":"Request failed with undefined","stack":"Error: Request failed with undefined\n    at Sendwithus._handleResponse (/var/task/node_modules/sendwithus/lib/sendwithus.js:110:15)\n    at /var/task/node_modules/sendwithus/lib/sendwithus.js:148:28\n    at processTicksAndRejections (internal/process/task_queues.js:97:5)","cause":{"message":"Request failed with undefined","stack":"Error: Request failed with undefined\n    at Sendwithus._handleResponse (/var/task/node_modules/sendwithus/lib/sendwithus.js:110:15)\n    at /var/task/node_modules/sendwithus/lib/sendwithus.js:148:28\n    at processTicksAndRejections (internal/process/task_queues.js:97:5)"},"isOperational":true} 

Steps to reproduce

call Sendwithus.send()

@demoore
Copy link
Member

demoore commented Aug 13, 2021

Thanks, @zeevl . To make this easier to reproduce can you let me know what version of node you're running and include an example of the send call you're making?

Thanks!

@zeevl
Copy link
Author

zeevl commented Aug 13, 2021

Glad you asked, I suspect this might be part of the problem! We're promisifying Sendwithus so we can use it with async/await..

import SendWithUs from 'sendwithus';
import bluebird from 'bluebird';

const sendwithus = bluebird.promisifyAll(SendWithUs(process.env.SEND_WITH_US_KEY));

  await sendwithus.sendAsync({
    email_id: emailId,
    recipient,
    sender,
    email_data: data,
  });

And this is running in node 12.x (whatever their current version is) in an AWS lambda function...

@kinano
Copy link

kinano commented Nov 8, 2021

I had the same issue when I updated from 4.3.1 to 4.3.3 to fix a build pipeline that broke when github turned off the unencrypted git protocol on November 2nd. I did not expect a patch version for this library to change a public API (I should have been more careful and skeptical).

I suggest adding a blurb on your readme to alert developers of this. Github will have a few more brownouts in the next few months and will remove support for unencrypted git protocol completely next March. I think it will be useful to help your community upgrade to a safe version that removes the unencrypted git protocol without breaking/changing the public stable API exposed in version 4.3.1.

https://github.blog/2021-09-01-improving-git-protocol-security-github/#when-are-these-changes-effective

The issue is caused by the reslter git:// url in package-lock.json generated by sendwithus 4.3.1. github shows the supported formats on their post.

"sendwithus": {
      "version": "4.3.1",
      "resolved": "https://registry.npmjs.org/sendwithus/-/sendwithus-4.3.1.tgz",
        ....
      "requires": {
        "restler": "git://github.com/sendwithus/restler.git#3.1.1"
      },
...
}

@iprignano
Copy link
Contributor

We also experienced what is reported here. The issue was introduced after restler got replaced by node-fetch. I've opened a PR to address this: #55

@officert
Copy link

ended up just writing my own SendWithUs client in all of about 5 mins. Here's the code if it's helpful for anyone else (uses Axios for HTTP client):

import axios from 'axios'
import SendWithUsApiError from '../errors/apiError'
import { SendWithUsSendEmailArgs } from '../types'

const BASE_URL = 'https://api.sendwithus.com/api/v1'

function handleError(error: any): SendWithUsApiError {
  let message = ''

  console.log('SENDWITHUS ERROR', error)

  if (error.response && error.response.data) {
    if (error.response.data.error) {
      message = error.response.data.error
    } else if (error.response.data.errors && error.response.data.errors.length) {
      message = JSON.stringify(error.response.data.errors)
    }
  }

  return new SendWithUsApiError(message)
}

const axiosInstance = axios.create({
  baseURL: BASE_URL,
})

class SendWithUsApiClient {
  async sendEmail(emailData: SendWithUsSendEmailArgs) {
    let result

    const apiKey = emailData.apiKey

    try {
      result = await axiosInstance({
        method: 'post',
        url: '/send',
        headers: {
          accept: 'application/json',
        },
        auth: {
          username: apiKey,
          password: '',
        },
        data: emailData,
      })
    } catch (error) {
      throw handleError(error)
    }

    return result.data
  }
}

export default new SendWithUsApiClient()

types:

export type SendwithUsFile = {
  id: string
  data: Buffer
}

export type SendWithUsSendEmailArgs = {
  apiKey: string
  template: string
  template_data?: object
  recipient: {
    address: string
    name?: string
  }
  sender: {
    address: string
    name?: string
    reply_to?: string
  }
  files?: Array<SendwithUsFile>
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants