publishlab / node-acme-client

Simple and unopinionated ACME client for Node.js
MIT License
272 stars 54 forks source link

Misleading error when HTTPS requests return non-success statuses #45

Closed silverwind closed 2 years ago

silverwind commented 3 years ago

When the directory URL returning a non-success status, the thrown error is rather misleading (it has nothing to do with dns resolution as one might be lead to think). For example:

# call client.createOrder()
acme-client HTTP request: get https://acme-v02.api.letsencrypt.org/directory +0ms
acme-client RESP 501 get https://acme-v02.api.letsencrypt.org/directory +12ms
# throws Error: Could not resolve URL for API resource: "newOrder"

That 501 here is caused by a axios bug (fixed in https://github.com/axios/axios/commit/e426910be7c417bdbcde9c18cb184ead826fc0e1) related to https proxy handling. I'd suggest to include the URL and statuscode in the thrown error message in such cases (e.g. when statuscode is not between 200 and 299).

nmorsman commented 2 years ago

Hi @silverwind and thanks for reporting this.

I've reworded the error you encountered to avoid future confusion, also added an extra check in case of failure to read the ACME directory in 0a0aea26507736bb89e37f5e6114d13ac54f8081.