sendgrid-nodejs icon indicating copy to clipboard operation
sendgrid-nodejs copied to clipboard

[bug] ResponseError#response#body has incorrect type

Open bogdan opened this issue 5 years ago • 2 comments

Issue Summary

ResponseError#response#body property has a type string assuming it is unparsed json string, but it is parsed json

Code Snippet

import sendgrid from '@sendgrid/mail';
import config from '../config';

sendgrid.setApiKey(config.SENDGRID_API_KEY)

sendgrid.send({
 to: '[email protected]',
  from: '[email protected]',
  subject: 'Test Subject',
  text: 'body',
  attachments: [{
    type: 'text',
    content: 'hello',
    filename: 'example.txt'
  }]
}).catch((error) => {
  console.log(typeof error.response.body)
}) 

Exception/Log

object

Ideally, I would want body to be extensively typed like {body: {errors: {message: string, field: string, help?:string}[]}

Technical details:

  • sendgrid-nodejs version: 7.4.0
  • node version: 12.18.1

bogdan avatar Nov 24 '20 15:11 bogdan

Hello @bogdan,

Thanks for taking the time to report this!

I'm re-classifying this to a feature request since the current behavior is not broken, but it could be optimized.

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

With best regards,

Elmer

thinkingserious avatar Jan 19 '21 22:01 thinkingserious

Well, there is a feature component into that in the "Ideally" section, but there is also a bug that type definition is incorrect.

bogdan avatar Jan 25 '21 14:01 bogdan