2

In this case, I am using an Express.js server to handle inbound Twilio webhooks and return an http response

However, I am seeing Twilio errors display in the debug console. This is the error Twilio displays in their console:

sourceComponent "14100"
ErrorCode   "12300"
LogLevel    "ERROR"
Msg "Invalid Content-Type: application/json; charset=utf-8 supplied"
contentType "application/json; charset=utf-8"
EmailNotification   "false"

I looked into overriding the Content-Type that is returned, but Express.js overrides this.

We're able to handle the inbound message so this doesn't seem fatal to my application, but should I be more concerned about this? Anything I should be looking into deeper?

I'm also looking into this similar problem (their app uses C#) where the answer seemed to be UTF8 encoding, but not sure if that solves the problem if Express.js overrides anyway

GPP
  • 2,157
  • 3
  • 18
  • 26

1 Answers1

1

You can use Express to return the appropriate MIME type, as defined here. Reference this repo to see the code.

TwilioQuest Starter Template Node

// Return an XML response to this request
  res.set('Content-Type','text/xml');
Alan
  • 10,465
  • 2
  • 8
  • 9
  • hi @Alan, Ive actually tried this and Express overrides and appends the `charset=utf-8` string – GPP Jan 28 '21 at 01:18
  • That should be ok, but text/xml, not application/json. – Alan Jan 28 '21 at 01:21
  • thanks Alan, do you recommend I utf-8 encode that as well? Or fine as is? – GPP Jan 29 '21 at 00:33
  • As a follow on @Alan, I found that even setting the header["Content-Type"] with `text/xml` the charset=utf-8 was still appended and caused another validation issue with Twilio. I'm surprised that twilio isn't aware of and sensitive to Express.js particularity – GPP Feb 05 '21 at 08:51
  • 1
    You can always open an issue on the repo with steps to reproduce, https://github.com/twilio/twilio-node/issues – Alan Feb 05 '21 at 14:18