Skip to content

The CLI cannot reach MockHub

A mockhub command that cannot connect to the API stops, exits 2, and names the address it tried and why the connection failed:

Cannot reach https://api.mockhub.io: getaddrinfo ENOTFOUND api.mockhub.io
Cannot reach https://api.mockhub.io: unable to get local issuer certificate (UNABLE_TO_GET_ISSUER_CERT_LOCALLY)
If the API uses a private or corporate CA, trust it with NODE_EXTRA_CA_CERTS=/path/to/ca.pem.

The part after the address is Node.js’s own message, followed by its code in brackets unless the message already holds it, as getaddrinfo ENOTFOUND api.mockhub.io does. The code says which cause below applies. The address is the one the CLI chose: MOCKHUB_API_URL first, then --api-url, then apiUrl in mockhub.yaml, and https://api.mockhub.io without any of them.

The name of the host could not be looked up: a typing mistake in the address, a machine without a network connection, or a DNS server that does not know the name, such as a private name only reachable on a company VPN.

  1. Check the address in the message. If it is not the one you meant, find which of MOCKHUB_API_URL, --api-url and apiUrl set it, and correct that one.
  2. Connect to the network or VPN the address needs, and run the command again.

ECONNREFUSED: nothing answers at that address

Section titled “ECONNREFUSED: nothing answers at that address”

The host exists, but refused the connection: nothing is listening on that port, as when the address names the wrong port, or a local proxy it points at is not running, or a firewall turns the connection away.

  1. Check the port in the address. Without one, the CLI connects to 443.
  2. If the address is a proxy or a tunnel of your own, start it, then run the command again.

ETIMEDOUT or UND_ERR_CONNECT_TIMEOUT: the connection was never answered

Section titled “ETIMEDOUT or UND_ERR_CONNECT_TIMEOUT: the connection was never answered”

The connection attempt got no answer at all, which is usually a firewall that drops outbound HTTPS, or a CI runner or container without internet access.

  1. From the same machine, check that the address answers over HTTPS at all, for example by opening it in a browser or with curl.
  2. On a CI runner, allow outbound HTTPS to the address, or run the job on a runner that has it.

A command that connects but waits too long for an answer says Timed out after 30000 ms waiting for and the request instead. MOCKHUB_TIMEOUT_MS sets how long each request may take; see CLI commands.

A certificate error: the certificate authority is not trusted

Section titled “A certificate error: the certificate authority is not trusted”

The connection reached a server whose certificate Node.js does not trust. The usual reason is a company proxy that inspects HTTPS and signs every site with the company’s own certificate authority, or an API address of your own whose certificate comes from a private one. The codes include:

Code Node.js says
UNABLE_TO_GET_ISSUER_CERT_LOCALLY unable to get local issuer certificate
UNABLE_TO_VERIFY_LEAF_SIGNATURE unable to verify the first certificate
SELF_SIGNED_CERT_IN_CHAIN self-signed certificate in certificate chain
DEPTH_ZERO_SELF_SIGNED_CERT self-signed certificate

For each of these the CLI adds the line If the API uses a private or corporate CA, trust it with NODE_EXTRA_CA_CERTS=/path/to/ca.pem.

  1. Get the certificate authority’s certificate as a PEM file, from whoever runs the proxy, such as your IT department.

  2. Name the file in NODE_EXTRA_CA_CERTS for the command. Node.js reads it once, when it starts, so set it on the same line or export it first:

    Terminal window
    NODE_EXTRA_CA_CERTS=/path/to/ca.pem mockhub diff
  3. On a CI runner, set NODE_EXTRA_CA_CERTS in the job’s environment, beside MOCKHUB_TOKEN.

The CLI has no option to skip certificate checks for the API; trust the certificate authority instead. The CLI adds the same line to CERT_HAS_EXPIRED and ERR_TLS_CERT_ALTNAME_INVALID, but trusting a certificate authority does not fix those: the certificate has expired, or was issued for another name, so the address points at the wrong server or the server needs a new certificate.

Report a problem with the full message, the command you ran, and the output of mockhub --version.

Report a problem with this page