diff --git a/ghost/prometheus-metrics/package.json b/ghost/prometheus-metrics/package.json index 7512a325de..ac054443a2 100644 --- a/ghost/prometheus-metrics/package.json +++ b/ghost/prometheus-metrics/package.json @@ -32,6 +32,7 @@ "typescript": "5.6.2" }, "dependencies": { + "@tryghost/errors": "1.3.6", "@tryghost/logging": "2.4.19", "express": "4.21.1", "prom-client": "15.1.3", diff --git a/ghost/prometheus-metrics/src/PrometheusClient.ts b/ghost/prometheus-metrics/src/PrometheusClient.ts index c09889f600..df760aee47 100644 --- a/ghost/prometheus-metrics/src/PrometheusClient.ts +++ b/ghost/prometheus-metrics/src/PrometheusClient.ts @@ -1,6 +1,7 @@ import {Request, Response} from 'express'; import client from 'prom-client'; import logging from '@tryghost/logging'; +import errors from '@tryghost/errors'; type PrometheusClientConfig = { register?: client.Registry; @@ -56,8 +57,14 @@ export class PrometheusClient { try { await this.gateway.pushAdd({jobName}); logging.debug('Metrics pushed to pushgateway - jobName: ', jobName); - } catch (error) { - logging.error('Error pushing metrics to pushgateway - jobName: ', jobName); + } catch (err) { + let error; + if (typeof err === 'object' && err !== null && 'code' in err) { + error = new errors.InternalServerError({message: 'Error pushing metrics to pushgateway: ' + err.code, code: err.code as string}); + } else { + error = new errors.InternalServerError({message: 'Error pushing metrics to pushgateway: Unknown error'}); + } + logging.error(error); } } } diff --git a/yarn.lock b/yarn.lock index 3b4361ed77..fd48b03cc2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7430,7 +7430,7 @@ focus-trap "^6.7.2" postcss-preset-env "^7.3.1" -"@tryghost/errors@1.3.1", "@tryghost/errors@1.3.5", "@tryghost/errors@^1.2.26", "@tryghost/errors@^1.2.3", "@tryghost/errors@^1.3.5", "@tryghost/errors@^1.3.6": +"@tryghost/errors@1.3.1", "@tryghost/errors@1.3.5", "@tryghost/errors@1.3.6", "@tryghost/errors@^1.2.26", "@tryghost/errors@^1.2.3", "@tryghost/errors@^1.3.5", "@tryghost/errors@^1.3.6": version "1.3.5" resolved "https://registry.yarnpkg.com/@tryghost/errors/-/errors-1.3.5.tgz#f4ef8e5c41a8a37456f2285271124180685827ae" integrity sha512-iOkiHGnYFqSdFM9AVlgiL56Qcx6V9iQ3kbDKxyOAxrhMKq1OnOmOm7tr1CgGK1YDte9XYEZmR9hUZEg+ujn/jQ==