hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.13k stars 2.76k forks source link

Action: Mutation response says content type of response is \"text/plain\ while my Twilio function is returning json a setting the right content type. #4342

Closed frossi85 closed 4 years ago

frossi85 commented 4 years ago

Hi,

I am trying to do phone verification using Twilio services, one of the involved services in the process is a Twilio function which is the handler for one of my Hasura Actions (I am running Hasura from master branch) but I am getting this error while executing the mutation:

Captura de Pantalla 2020-04-08 a la(s) 21 38 24

Here is the Twillio function code:

exports.handler = function(context, event, callback) {
  const response = new Twilio.Response();

  //  -----> HERE IS WHERE I SET THE RIGHT CONTENT TYPE
  response.appendHeader('Content-Type', 'application/json');

  // CORS support
  response.appendHeader('Access-Control-Allow-Origin', '*'); // for testing, restrict to your website in prod!
  response.appendHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
  response.appendHeader('Access-Control-Allow-Headers', 'Content-Type');

  const client = context.getTwilioClient();
  const service = context.VERIFY_SERVICE_SID

  const channel = (typeof event.channel === 'undefined') ? "sms" : event.channel;
  const to = event.phoneNumber;

  client.verify.services(service)
    .verifications
    .create({to: to, channel: channel})
    .then(verification => {
      verification.success = true;

     //  -----> HERE verification IS AN OBJECT
      response.setBody(verification);

      response.setStatusCode(200);
      callback(null, response);
    })
    .catch(error => {
      response.setBody({
        "success": false,
        "message": error
      })
      response.setStatusCode(400);
      callback(null, response);
    });
};

This is the result of calling that function from Insomnia:

Captura de Pantalla 2020-04-08 a la(s) 21 26 11 Captura de Pantalla 2020-04-08 a la(s) 21 24 59

As you can see in the images the response type is JSON.

My Postres version was 11.7, then I upgraded it to 12.2 but the issue still remains.

Any idea why this could be happening? Error and longs in Heroku do not help me to know why this is failing.

frossi85 commented 4 years ago

Ok, my fault the issue was that Handler comes populated with a placeholder url and when I pasted the real url some parts of that placehoder remained there.

Sorry, I will close it.