Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

bug: createDnsRecord throws "undefined method `end_with?' for nil:NilClass" #107

Open
CanRau opened this issue Jun 14, 2020 · 8 comments
Open

Comments

@CanRau
Copy link

CanRau commented Jun 14, 2020

- Do you want to request a feature or report a bug?
This is a bug report

- What is the current behavior?
Trying to create DNS records using

const NetlifyAPI = require("netlify");
const client = new NetlifyAPI("TOKE");
(async () => {
  const dnsZone = await client.getDNSForSite({
    site_id: "SITE_ID",
  });
  await client.createDnsRecord({
    zone_id: dnsZone[0].id,
    type: record.type,
    hostname: record.name,
    value: record.value,
  });
})();

throws the following error

ERROR: JSONHTTPError: Internal Server Error
    at parseResponse ([..]/node_modules/netlify/src/methods/response.js:12:11)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async callMethod ([..]/node_modules/netlify/src/methods/index.js:38:26)
    at async [..]/netlify-create-dns.js:17:7 {
  name: 'JSONHTTPError',
  status: 500,
  json: { error: "undefined method `end_with?' for nil:NilClass" }
}

It's already been brought up in the community

- If the current behavior is a bug, please provide the steps to reproduce.
Using the code from above using a valid API token and correct site id found in https://app.netlify.com/sites/SITE_NAME/settings/general -> Site Information: APP ID

- What is the expected behavior?
Creation of DNS records.

- Please mention your node.js, and operating system version.
NodeJS v12.14.1, macOS 10.14.6

@ehmicky
Copy link
Contributor

ehmicky commented Jun 29, 2020

Related: netlify/open-api#240

@ehmicky
Copy link
Contributor

ehmicky commented Jun 29, 2020

Hi @CanRau,

Could you please try to send the same request but directly via HTTP (e.g. with curl or other similar tools) as suggested in netlify/open-api#240?

This would allow making sure this is an API bug (which it seems to be) and not a bug in js-client. Thanks!

@CanRau
Copy link
Author

CanRau commented Jul 2, 2020

Sure 🤝
I copy pasted the example from netlify/open-api#240 (comment), replaced API token & DNS zone id and received the same error

{"error":"undefined method `end_with?' for nil:NilClass"}

@ehmicky
Copy link
Contributor

ehmicky commented Jul 2, 2020

Thanks @CanRau.

This means this is not a problem related to the js-client but to our API. I am forwarding this to our API team.

@vbrown608 @kitop @keiko713 Do you know what the problem might be?

@CanRau
Copy link
Author

CanRau commented Jul 2, 2020

Sounds reasonable 😊👌

@kitop
Copy link
Contributor

kitop commented Jul 2, 2020

I'll file a bug on API.

I'm curious to see the value of hostname: record.name, that was sent in the original report.

For the one copied from open-api issue, did you set the Content-Type to application/json? That's missing in the original curl example in the issue.

@kitop
Copy link
Contributor

kitop commented Jul 3, 2020

We deployed fix to API now that handles this. You should get a more helpful error message now.

@CanRau Can you please try again and let us know?

@CanRau
Copy link
Author

CanRau commented Jul 4, 2020

Looks great 👏
cURL without content type header responds now with more useful error

{"errors":{"type":["can't be blank","record type  is unsupported for api provider ns1"],"hostname":["can't be blank"],"value":["can't be blank"]}}

even though it wasn't directly clear to me that it's related to the content type 😅

With the content type set

curl -H 'Authorization: Bearer [API_TOKEN]' -H "Content-Type: application/json" \
     --data \
     '{"type":"A",
       "hostname":"junk.example.net",
       "value":"192.168.0.1",
       "ttl":3600,
       "priority":null,
       "weight":null,
       "port":null,
       "flag":null,
       "tag":null}' \
     https://api.netlify.com/api/v1/dns_zones/[ZONE_ID]/dns_records/

it works as expected and returns the result correctly

{"hostname":"junk.example.net.gaiama.org","type":"A","ttl":3600,"priority":null,"weight":null,"port":null,"flag":null,"tag":null,"id":"[ID]","site_id":null,"dns_zone_id":"[ZONE_ID]","errors":[],"managed":false,"value":"192.168.0.1"}

can't get the js client working though, even after updating to 4.3.5

client.createDnsRecord({
  zone_id: dnsZone[0].id,
  type: record.type,
  hostname: record.name,
  value: record.value,
});

feeding it those values

{
    "type": "A",
    "name": "TEST",
    "value": "192.168.0.1"
}

resulting in the following error

JSONHTTPError: Unprocessable Entity
    at parseResponse ([..]/node_modules/netlify/src/methods/response.js:12:11)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async callMethod ([..]/node_modules/netlify/src/methods/index.js:36:26)
    at async [..]/netlify-create-dns.js:21:7 {
  name: 'JSONHTTPError',
  status: 422,
  json: {
  "errors": {
    "type": [
      "can't be blank",
      "record type  is unsupported for api provider ns1"
    ],
    "hostname": [
      "can't be blank"
    ],
    "value": [
      "can't be blank"
    ]
  }
}
}

I logged all values and all are valid strings 🤷‍♂️

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

No branches or pull requests

3 participants