diff --git a/packages/dashmate/src/ssl/zerossl/createCertificate.js b/packages/dashmate/src/ssl/zerossl/createCertificate.js index 59fd207dcc6..bc8fe083888 100644 --- a/packages/dashmate/src/ssl/zerossl/createCertificate.js +++ b/packages/dashmate/src/ssl/zerossl/createCertificate.js @@ -1,5 +1,6 @@ const fetch = require('node-fetch'); const qs = require('qs'); +const errorDescriptions = require('./errors/errorDescriptions'); /** * Create a ZeroSSL Certificate @@ -36,7 +37,9 @@ async function createCertificate( const data = await response.json(); if (data.error) { - throw new Error(JSON.stringify(data.error)); + const errorMessage = errorDescriptions[data.error.code]; + + throw new Error(errorMessage || JSON.stringify(data.error)); } return data; diff --git a/packages/dashmate/src/ssl/zerossl/downloadCertificate.js b/packages/dashmate/src/ssl/zerossl/downloadCertificate.js index ddf768b4912..5974388a547 100644 --- a/packages/dashmate/src/ssl/zerossl/downloadCertificate.js +++ b/packages/dashmate/src/ssl/zerossl/downloadCertificate.js @@ -1,5 +1,6 @@ const fetch = require('node-fetch'); const wait = require('../../util/wait'); +const errorDescriptions = require('./errors/errorDescriptions'); /** * Download the certificate specified by id @@ -40,7 +41,9 @@ async function downloadCertificate(id, apiKey) { } if (data.error) { - throw new Error(data.error.type); + const errorMessage = errorDescriptions[data.error.code]; + + throw new Error(errorMessage || JSON.stringify(data.error)); } return `${data['certificate.crt']}\n${data['ca_bundle.crt']}`; diff --git a/packages/dashmate/src/ssl/zerossl/errors/errorDescriptions.js b/packages/dashmate/src/ssl/zerossl/errors/errorDescriptions.js new file mode 100644 index 00000000000..5bff868ae94 --- /dev/null +++ b/packages/dashmate/src/ssl/zerossl/errors/errorDescriptions.js @@ -0,0 +1,24 @@ +module.exports = { + 2804: 'The current certificate cannot be issued due to unpaid invoices on your ZeroSSL account.', + 2808: 'Your domain is not valid', + 2813: 'Only issued certificates can be renewed or replaced by a new certificate.', + 2814: 'Yo do not have the permissions to access ZeroSSL certificate to renew.', + 2815: 'Only issued certificates can be renewed or replaced by a new certificate.', + 2816: 'ZeroSSL certificate to renew was not found.', + 2817: 'Limit of certificates on your ZeroSSL account was reached', + 2820: 'Internal error processing CSR. Please contact ZeroSSL support if this error occurs.', + 2821: 'Internal error generating certificate. Please contact ZeroSSL support if this error occurs.', + 2839: 'ZeroSSL requires an upgrade from Free Plan to Basic Plan', + 2841: 'Your ZeroSSL account has been temporarily suspended due to unpaid invoices', + 101: 'ZeroSSL API key is invalid', + 102: 'Your ZeroSSL account is not active', + 111: 'Something went wrong. If the problem persists please contact ZeroSSL support team (support@zerossl.com)', + 2801: 'You do not have the permissions to access ZeroSSL resource', + 2803: 'Your ZeroSSL certificate ID (hash) could not be found', + 2822: 'The requested ZeroSSL certificate could not be retrieved.', + 2823: 'ZeroSSL domain verification failed and must be retried.', + 2826: 'Internal error verifying domains. Please contact ZeroSSL support if this error occurs', + 2874: 'ZeroSSL is not able to issue certificates for this Top-Level-Domain at the moment', + 2832: 'The given certificate has not been issued yet', + 2860: 'The certificate can currently not be downloaded', +}; diff --git a/packages/dashmate/src/ssl/zerossl/getCertificate.js b/packages/dashmate/src/ssl/zerossl/getCertificate.js index 8fc55a2dd41..d9b9ff228ae 100644 --- a/packages/dashmate/src/ssl/zerossl/getCertificate.js +++ b/packages/dashmate/src/ssl/zerossl/getCertificate.js @@ -1,4 +1,5 @@ const fetch = require('node-fetch'); +const errorDescriptions = require('./errors/errorDescriptions'); /** * Get ZeroSSL certificate @@ -21,7 +22,9 @@ async function getCertificate(apiKey, id) { const data = await response.json(); if (data.error) { - throw new Error(data.error.type); + const errorMessage = errorDescriptions[data.error.code]; + + throw new Error(errorMessage || JSON.stringify(data.error)); } return data; diff --git a/packages/dashmate/src/ssl/zerossl/listCertificates.js b/packages/dashmate/src/ssl/zerossl/listCertificates.js index a6ac9b03046..c2eadd6a25a 100644 --- a/packages/dashmate/src/ssl/zerossl/listCertificates.js +++ b/packages/dashmate/src/ssl/zerossl/listCertificates.js @@ -1,4 +1,5 @@ const fetch = require('node-fetch'); +const errorDescriptions = require('./errors/errorDescriptions'); /** * List ZeroSSL certificates @@ -20,7 +21,9 @@ async function listCertificates(apiKey) { const data = await response.json(); if (data.error) { - throw new Error(data.error.type); + const errorMessage = errorDescriptions[data.error.code]; + + throw new Error(errorMessage || JSON.stringify(data.error)); } return data; diff --git a/packages/dashmate/src/ssl/zerossl/verifyDomain.js b/packages/dashmate/src/ssl/zerossl/verifyDomain.js index 2a1d79a877a..f67f2f883ff 100644 --- a/packages/dashmate/src/ssl/zerossl/verifyDomain.js +++ b/packages/dashmate/src/ssl/zerossl/verifyDomain.js @@ -1,6 +1,7 @@ const fetch = require('node-fetch'); const qs = require('qs'); +const errorDescriptions = require('./errors/errorDescriptions'); /** * Verify the domain/ip specified by certificate id @@ -30,7 +31,9 @@ async function verifyDomain(id, apiKey) { const data = await response.json(); if (data.error) { - throw new Error(data.error.type); + const errorMessage = errorDescriptions[data.error.code]; + + throw new Error(errorMessage || JSON.stringify(data.error)); } return data;