pexels / pexels-javascript

Official Javascript library for the Pexels API.
https://www.pexels.com/api/documentation/
145 stars 29 forks source link

CERT_HAS_EXPIRED error #54

Closed amythical closed 4 months ago

amythical commented 4 months ago

Intermittently getting a certificate error

FetchError: request to https://api.pexels.com/v1//curated?page=1&per_page=40 failed, reason: certificate has expired at ClientRequest. (/myapp/node_modules/pexels/node_modules/node-fetch/lib/index.js:1483:11) at emitOne (events.js:116:13) at ClientRequest.emit (events.js:211:7) at TLSSocket.socketErrorListener (_http_client.js:387:9) at emitOne (events.js:116:13) at TLSSocket.emit (events.js:211:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickDomainCallback (internal/process/next_tick.js:218:9) message: 'request to https://api.pexels.com/v1//curated?page=1&per_page=40 failed, reason: certificate has expired', type: 'system', errno: 'CERT_HAS_EXPIRED', code: 'CERT_HAS_EXPIRED'

Tried removing and reinstalling the module but did not work. What worked is sometimes on uninstalling and re-installing node this worked. Sometimes npm clean cache also fixes this error. But these are intermittent fixes.

amythical commented 4 months ago

Found a fix. TLDR - letsencrypt certificate expired so openssl bundled with node(mine was 8.10.0) throws this error. Use a httpsagent with the new certificate from letsencrypt. Fix detailed in the links. Solution in this link - https://stackoverflow.com/questions/69414479/giving-axios-letsencrypts-new-root-certificate-on-old-version-of-node