From d78e4e4ab0c42a03ad287e466af66cf3efe301e6 Mon Sep 17 00:00:00 2001 From: chris48s Date: Fri, 2 Jun 2023 19:49:42 +0100 Subject: [PATCH 1/6] allow serviceData to override cacheSeconds with a longer value --- core/base-service/cache-headers.js | 2 +- core/base-service/cache-headers.spec.js | 4 ++-- core/base-service/legacy-request-handler.js | 8 +++----- core/base-service/legacy-request-handler.spec.js | 6 +++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/core/base-service/cache-headers.js b/core/base-service/cache-headers.js index 14a707efae7e3..2bd02e2f161e4 100644 --- a/core/base-service/cache-headers.js +++ b/core/base-service/cache-headers.js @@ -39,6 +39,7 @@ function coalesceCacheLength({ assert(defaultCacheLengthSeconds !== undefined) const cacheLength = coalesce( + serviceOverrideCacheLengthSeconds, serviceDefaultCacheLengthSeconds, defaultCacheLengthSeconds ) @@ -46,7 +47,6 @@ function coalesceCacheLength({ // Overrides can apply _more_ caching, but not less. Query param overriding // can request more overriding than service override, but not less. const candidateOverrides = [ - serviceOverrideCacheLengthSeconds, overrideCacheLengthFromQueryParams(queryParams), ].filter(x => x !== undefined) diff --git a/core/base-service/cache-headers.spec.js b/core/base-service/cache-headers.spec.js index ebfc53f815243..fcf82ee749fd7 100644 --- a/core/base-service/cache-headers.spec.js +++ b/core/base-service/cache-headers.spec.js @@ -74,12 +74,12 @@ describe('Cache header functions', function () { serviceDefaultCacheLengthSeconds: 900, serviceOverrideCacheLengthSeconds: 400, queryParams: {}, - }).expect(900) + }).expect(400) given({ cacheHeaderConfig, serviceOverrideCacheLengthSeconds: 400, queryParams: {}, - }).expect(777) + }).expect(400) given({ cacheHeaderConfig, serviceOverrideCacheLengthSeconds: 900, diff --git a/core/base-service/legacy-request-handler.js b/core/base-service/legacy-request-handler.js index 2e5b7e92b9a2a..9ef3d4efeb4b5 100644 --- a/core/base-service/legacy-request-handler.js +++ b/core/base-service/legacy-request-handler.js @@ -73,11 +73,9 @@ function handleRequest(cacheHeaderConfig, handlerOptions) { // `defaultCacheLengthSeconds` can be overridden by // `serviceDefaultCacheLengthSeconds` (either by category or on a badge- // by-badge basis). Then in turn that can be overridden by - // `serviceOverrideCacheLengthSeconds` (which we expect to be used only in - // the dynamic badge) but only if `serviceOverrideCacheLengthSeconds` is - // longer than `serviceDefaultCacheLengthSeconds` and then the `cacheSeconds` - // query param can also override both of those but again only if `cacheSeconds` - // is longer. + // `serviceOverrideCacheLengthSeconds`. + // Then the `cacheSeconds` query param can also override both of those + // but only if `cacheSeconds` is longer. // // When the legacy services have been rewritten, all the code in here // will go away, which should achieve this goal in a simpler way. diff --git a/core/base-service/legacy-request-handler.spec.js b/core/base-service/legacy-request-handler.spec.js index 2265f18e69eb3..9293e42ecacd9 100644 --- a/core/base-service/legacy-request-handler.spec.js +++ b/core/base-service/legacy-request-handler.spec.js @@ -148,7 +148,7 @@ describe('The request handler', function () { expect(headers['cache-control']).to.equal('max-age=900, s-maxage=900') }) - it('should let live service data override the default cache headers with longer value', async function () { + it('should allow serviceData to override the default cache headers with longer value', async function () { camp.route( /^\/testing\/([^/]+)\.(svg|png|gif|jpg|json)$/, handleRequest( @@ -168,7 +168,7 @@ describe('The request handler', function () { expect(headers['cache-control']).to.equal('max-age=400, s-maxage=400') }) - it('should not let live service data override the default cache headers with shorter value', async function () { + it('should allow serviceData to override the default cache headers with shorter value', async function () { camp.route( /^\/testing\/([^/]+)\.(svg|png|gif|jpg|json)$/, handleRequest( @@ -185,7 +185,7 @@ describe('The request handler', function () { ) const { headers } = await got(`${baseUrl}/testing/123.json`) - expect(headers['cache-control']).to.equal('max-age=300, s-maxage=300') + expect(headers['cache-control']).to.equal('max-age=200, s-maxage=200') }) it('should set the expires header to current time + cacheSeconds', async function () { From 2865b2da778be26fc2059ac11d63bcd4cea1b331 Mon Sep 17 00:00:00 2001 From: chris48s Date: Fri, 2 Jun 2023 19:52:24 +0100 Subject: [PATCH 2/6] prevent [endpoint] json cacheSeconds property exceeding service default --- services/endpoint/endpoint.service.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/endpoint/endpoint.service.js b/services/endpoint/endpoint.service.js index 26be6f8402de4..4a33259df29a7 100644 --- a/services/endpoint/endpoint.service.js +++ b/services/endpoint/endpoint.service.js @@ -178,7 +178,10 @@ export default class Endpoint extends BaseJsonService { logoWidth, logoPosition, style, - cacheSeconds, + // don't allow the user to set cacheSeconds any shorter than this._cacheLength + cacheSeconds: Math.max( + ...[this._cacheLength, cacheSeconds].filter(x => x !== undefined) + ), } } From fb9c636f38b48cf491a4d113ca265323f4d022bd Mon Sep 17 00:00:00 2001 From: chris48s Date: Fri, 2 Jun 2023 19:56:44 +0100 Subject: [PATCH 3/6] allow ShieldsRuntimeError to specify a cacheSeconds property By default error responses use the cacheLength of the service class throwing the error. This allows error to tell the handling layer the maxAge that should be set on the error badge response. --- core/base-service/errors.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/base-service/errors.js b/core/base-service/errors.js index a1c897ff6d0e9..ce90f199d2640 100644 --- a/core/base-service/errors.js +++ b/core/base-service/errors.js @@ -42,6 +42,7 @@ class ShieldsRuntimeError extends Error { if (props.underlyingError) { this.stack = props.underlyingError.stack } + this.cacheSeconds = props.cacheSeconds } } @@ -206,6 +207,9 @@ class Deprecated extends ShieldsRuntimeError { * @property {string} prettyMessage User-facing error message to override the * value of `defaultPrettyMessage()`. This is the text that will appear on the * badge when we catch and render the exception (Optional) + * @property {number} cacheSeconds Length of time to cache this error response + * for. Defaults to the cacheLength of the service class throwing the error + * (Optional) */ export { From 0ac8fb699fecfdb4306430291b9641b3f16e5c63 Mon Sep 17 00:00:00 2001 From: chris48s Date: Fri, 2 Jun 2023 20:10:30 +0100 Subject: [PATCH 4/6] add customExceptions param This 1. allows us to specify custom properties to pass to the exception constructor if we throw any of the standard got errors e.g: `ETIMEDOUT`, `ECONNRESET`, etc 2. uses a custom `cacheSeconds` property (if set on the exception) to set the response maxAge --- core/base-service/base-graphql.js | 8 +++++++ core/base-service/base-json.js | 15 ++++++++++++- core/base-service/base-svg-scraping.js | 8 +++++++ core/base-service/base-xml.js | 8 +++++++ core/base-service/base-yaml.js | 8 +++++++ core/base-service/base.js | 19 +++++++++++++--- core/base-service/got.js | 13 ++++++++++- core/base-service/got.spec.js | 30 ++++++++++++++++++++++++++ 8 files changed, 104 insertions(+), 5 deletions(-) diff --git a/core/base-service/base-graphql.js b/core/base-service/base-graphql.js index 694a2f2720125..a954b0660f62f 100644 --- a/core/base-service/base-graphql.js +++ b/core/base-service/base-graphql.js @@ -44,6 +44,12 @@ class BaseGraphqlService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) + * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * and an object of params to pass when we construct an Inaccessible exception object + * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. + * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} + * for allowed keys + * and {@link module:core/base-service/errors~RuntimeErrorProps} for allowed values * @param {Function} [attrs.transformJson=data => data] Function which takes the raw json and transforms it before * further procesing. In case of multiple query in a single graphql call and few of them * throw error, partial data might be used ignoring the error. @@ -62,6 +68,7 @@ class BaseGraphqlService extends BaseService { variables = {}, options = {}, httpErrorMessages = {}, + customExceptions = {}, transformJson = data => data, transformErrors = defaultTransformErrors, }) { @@ -75,6 +82,7 @@ class BaseGraphqlService extends BaseService { url, options: mergedOptions, errorMessages: httpErrorMessages, + customExceptions, }) const json = transformJson(this._parseJson(buffer)) if (json.errors) { diff --git a/core/base-service/base-json.js b/core/base-service/base-json.js index ebabf1a41652d..410f3287f2b8d 100644 --- a/core/base-service/base-json.js +++ b/core/base-service/base-json.js @@ -34,10 +34,22 @@ class BaseJsonService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) + * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * and an object of params to pass when we construct an Inaccessible exception object + * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. + * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} + * for allowed keys + * and {@link module:core/base-service/errors~RuntimeErrorProps} for allowed values * @returns {object} Parsed response * @see https://github.com/sindresorhus/got/blob/main/documentation/2-options.md */ - async _requestJson({ schema, url, options = {}, errorMessages = {} }) { + async _requestJson({ + schema, + url, + options = {}, + errorMessages = {}, + customExceptions = {}, + }) { const mergedOptions = { ...{ headers: { Accept: 'application/json' } }, ...options, @@ -46,6 +58,7 @@ class BaseJsonService extends BaseService { url, options: mergedOptions, errorMessages, + customExceptions, }) const json = this._parseJson(buffer) return this.constructor._validate(json, schema) diff --git a/core/base-service/base-svg-scraping.js b/core/base-service/base-svg-scraping.js index a1cf981857611..10635a291283f 100644 --- a/core/base-service/base-svg-scraping.js +++ b/core/base-service/base-svg-scraping.js @@ -57,6 +57,12 @@ class BaseSvgScrapingService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) + * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * and an object of params to pass when we construct an Inaccessible exception object + * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. + * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} + * for allowed keys + * and {@link module:core/base-service/errors~RuntimeErrorProps} for allowed values * @returns {object} Parsed response * @see https://github.com/sindresorhus/got/blob/main/documentation/2-options.md */ @@ -66,6 +72,7 @@ class BaseSvgScrapingService extends BaseService { url, options = {}, errorMessages = {}, + customExceptions = {}, }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) const mergedOptions = { @@ -76,6 +83,7 @@ class BaseSvgScrapingService extends BaseService { url, options: mergedOptions, errorMessages, + customExceptions, }) logTrace(emojic.dart, 'Response SVG', buffer) const data = { diff --git a/core/base-service/base-xml.js b/core/base-service/base-xml.js index d758781c39d93..f450a3105a447 100644 --- a/core/base-service/base-xml.js +++ b/core/base-service/base-xml.js @@ -28,6 +28,12 @@ class BaseXmlService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) + * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * and an object of params to pass when we construct an Inaccessible exception object + * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. + * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} + * for allowed keys + * and {@link module:core/base-service/errors~RuntimeErrorProps} for allowed values * @param {object} [attrs.parserOptions={}] Options to pass to fast-xml-parser. See * [documentation](https://github.com/NaturalIntelligence/fast-xml-parser#xml-to-json) * @returns {object} Parsed response @@ -39,6 +45,7 @@ class BaseXmlService extends BaseService { url, options = {}, errorMessages = {}, + customExceptions = {}, parserOptions = {}, }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) @@ -50,6 +57,7 @@ class BaseXmlService extends BaseService { url, options: mergedOptions, errorMessages, + customExceptions, }) const validateResult = XMLValidator.validate(buffer) if (validateResult !== true) { diff --git a/core/base-service/base-yaml.js b/core/base-service/base-yaml.js index 85e08f2d25c18..df78d842a6126 100644 --- a/core/base-service/base-yaml.js +++ b/core/base-service/base-yaml.js @@ -27,6 +27,12 @@ class BaseYamlService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) + * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * and an object of params to pass when we construct an Inaccessible exception object + * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. + * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} + * for allowed keys + * and {@link module:core/base-service/errors~RuntimeErrorProps} for allowed values * @param {object} [attrs.encoding='utf8'] Character encoding * @returns {object} Parsed response * @see https://github.com/sindresorhus/got/blob/main/documentation/2-options.md @@ -36,6 +42,7 @@ class BaseYamlService extends BaseService { url, options = {}, errorMessages = {}, + customExceptions = {}, encoding = 'utf8', }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) @@ -52,6 +59,7 @@ class BaseYamlService extends BaseService { url, options: mergedOptions, errorMessages, + customExceptions, }) let parsed try { diff --git a/core/base-service/base.js b/core/base-service/base.js index f60470fa3ba78..a8c12a9b232ba 100644 --- a/core/base-service/base.js +++ b/core/base-service/base.js @@ -226,7 +226,12 @@ class BaseService { this._metricHelper = metricHelper } - async _request({ url, options = {}, errorMessages = {} }) { + async _request({ + url, + options = {}, + errorMessages = {}, + customExceptions = {}, + }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) let logUrl = url const logOptions = Object.assign({}, options) @@ -246,7 +251,11 @@ class BaseService { 'Request', `${logUrl}\n${JSON.stringify(logOptions, null, 2)}` ) - const { res, buffer } = await this._requestFetcher(url, options) + const { res, buffer } = await this._requestFetcher( + url, + options, + customExceptions + ) await this._meterResponse(res, buffer) logTrace(emojic.dart, 'Response status code', res.statusCode) return checkErrorResponse(errorMessages)({ buffer, res }) @@ -328,11 +337,15 @@ class BaseService { error instanceof Deprecated ) { trace.logTrace('outbound', emojic.noGoodWoman, 'Handled error', error) - return { + const serviceData = { isError: true, message: error.prettyMessage, color: 'lightgray', } + if (error.cacheSeconds !== undefined) { + serviceData.cacheSeconds = error.cacheSeconds + } + return serviceData } else if (this._handleInternalErrors) { if ( !trace.logTrace( diff --git a/core/base-service/got.js b/core/base-service/got.js index 773aa3b57ffd3..e9b1e1d1ce924 100644 --- a/core/base-service/got.js +++ b/core/base-service/got.js @@ -7,7 +7,12 @@ import { const userAgent = getUserAgent() -async function sendRequest(gotWrapper, url, options) { +async function sendRequest( + gotWrapper, + url, + options = {}, + customExceptions = {} +) { const gotOptions = Object.assign({}, options) gotOptions.throwHttpErrors = false gotOptions.retry = { limit: 0 } @@ -22,6 +27,12 @@ async function sendRequest(gotWrapper, url, options) { underlyingError: new Error('Maximum response size exceeded'), }) } + if (err.code in customExceptions) { + throw new Inaccessible({ + ...customExceptions[err.code], + underlyingError: err, + }) + } throw new Inaccessible({ underlyingError: err }) } } diff --git a/core/base-service/got.spec.js b/core/base-service/got.spec.js index 004ee667a1bca..37b201f0f5752 100644 --- a/core/base-service/got.spec.js +++ b/core/base-service/got.spec.js @@ -45,6 +45,36 @@ describe('got wrapper', function () { ) }) + it('should throw a custom error if provided', async function () { + const sendRequest = _fetchFactory(1024) + return ( + expect( + sendRequest( + 'https://www.google.com/foo/bar', + { timeout: { request: 1 } }, + { + ETIMEDOUT: { + prettyMessage: 'Oh no! A terrible thing has happened', + cacheSeconds: 10, + }, + } + ) + ) + .to.be.rejectedWith( + Inaccessible, + "Inaccessible: Timeout awaiting 'request' for 1ms" + ) + // eslint-disable-next-line promise/prefer-await-to-then + .then(error => { + expect(error).to.have.property( + 'prettyMessage', + 'Oh no! A terrible thing has happened' + ) + expect(error).to.have.property('cacheSeconds', 10) + }) + ) + }) + it('should pass a custom user agent header', async function () { nock('https://www.google.com', { reqheaders: { From d52b475aa3cbea025aa6c5e4c028c332494c94e8 Mon Sep 17 00:00:00 2001 From: chris48s Date: Mon, 12 Jun 2023 13:01:52 +0100 Subject: [PATCH 5/6] customExceptions --> systemErrors --- core/base-service/base-graphql.js | 6 +++--- core/base-service/base-json.js | 6 +++--- core/base-service/base-svg-scraping.js | 6 +++--- core/base-service/base-xml.js | 6 +++--- core/base-service/base-yaml.js | 6 +++--- core/base-service/base.js | 9 ++------- core/base-service/got.js | 11 +++-------- 7 files changed, 20 insertions(+), 30 deletions(-) diff --git a/core/base-service/base-graphql.js b/core/base-service/base-graphql.js index a954b0660f62f..646982f2655dc 100644 --- a/core/base-service/base-graphql.js +++ b/core/base-service/base-graphql.js @@ -44,7 +44,7 @@ class BaseGraphqlService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) - * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * @param {object} [attrs.systemErrors={}] Key-value map of got network exception codes * and an object of params to pass when we construct an Inaccessible exception object * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} @@ -68,7 +68,7 @@ class BaseGraphqlService extends BaseService { variables = {}, options = {}, httpErrorMessages = {}, - customExceptions = {}, + systemErrors = {}, transformJson = data => data, transformErrors = defaultTransformErrors, }) { @@ -82,7 +82,7 @@ class BaseGraphqlService extends BaseService { url, options: mergedOptions, errorMessages: httpErrorMessages, - customExceptions, + systemErrors, }) const json = transformJson(this._parseJson(buffer)) if (json.errors) { diff --git a/core/base-service/base-json.js b/core/base-service/base-json.js index 410f3287f2b8d..0a559cf5a2f2b 100644 --- a/core/base-service/base-json.js +++ b/core/base-service/base-json.js @@ -34,7 +34,7 @@ class BaseJsonService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) - * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * @param {object} [attrs.systemErrors={}] Key-value map of got network exception codes * and an object of params to pass when we construct an Inaccessible exception object * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} @@ -48,7 +48,7 @@ class BaseJsonService extends BaseService { url, options = {}, errorMessages = {}, - customExceptions = {}, + systemErrors = {}, }) { const mergedOptions = { ...{ headers: { Accept: 'application/json' } }, @@ -58,7 +58,7 @@ class BaseJsonService extends BaseService { url, options: mergedOptions, errorMessages, - customExceptions, + systemErrors, }) const json = this._parseJson(buffer) return this.constructor._validate(json, schema) diff --git a/core/base-service/base-svg-scraping.js b/core/base-service/base-svg-scraping.js index 10635a291283f..bc171f18dafd1 100644 --- a/core/base-service/base-svg-scraping.js +++ b/core/base-service/base-svg-scraping.js @@ -57,7 +57,7 @@ class BaseSvgScrapingService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) - * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * @param {object} [attrs.systemErrors={}] Key-value map of got network exception codes * and an object of params to pass when we construct an Inaccessible exception object * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} @@ -72,7 +72,7 @@ class BaseSvgScrapingService extends BaseService { url, options = {}, errorMessages = {}, - customExceptions = {}, + systemErrors = {}, }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) const mergedOptions = { @@ -83,7 +83,7 @@ class BaseSvgScrapingService extends BaseService { url, options: mergedOptions, errorMessages, - customExceptions, + systemErrors, }) logTrace(emojic.dart, 'Response SVG', buffer) const data = { diff --git a/core/base-service/base-xml.js b/core/base-service/base-xml.js index f450a3105a447..57c0270ea38b9 100644 --- a/core/base-service/base-xml.js +++ b/core/base-service/base-xml.js @@ -28,7 +28,7 @@ class BaseXmlService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) - * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * @param {object} [attrs.systemErrors={}] Key-value map of got network exception codes * and an object of params to pass when we construct an Inaccessible exception object * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} @@ -45,7 +45,7 @@ class BaseXmlService extends BaseService { url, options = {}, errorMessages = {}, - customExceptions = {}, + systemErrors = {}, parserOptions = {}, }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) @@ -57,7 +57,7 @@ class BaseXmlService extends BaseService { url, options: mergedOptions, errorMessages, - customExceptions, + systemErrors, }) const validateResult = XMLValidator.validate(buffer) if (validateResult !== true) { diff --git a/core/base-service/base-yaml.js b/core/base-service/base-yaml.js index df78d842a6126..a17b394aa99d3 100644 --- a/core/base-service/base-yaml.js +++ b/core/base-service/base-yaml.js @@ -27,7 +27,7 @@ class BaseYamlService extends BaseService { * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) - * @param {object} [attrs.customExceptions={}] Key-value map of got network exception codes + * @param {object} [attrs.systemErrors={}] Key-value map of got network exception codes * and an object of params to pass when we construct an Inaccessible exception object * e.g: `{ ECONNRESET: { prettyMessage: 'connection reset' } }`. * See {@link https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#errorcodes got error codes} @@ -42,7 +42,7 @@ class BaseYamlService extends BaseService { url, options = {}, errorMessages = {}, - customExceptions = {}, + systemErrors = {}, encoding = 'utf8', }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) @@ -59,7 +59,7 @@ class BaseYamlService extends BaseService { url, options: mergedOptions, errorMessages, - customExceptions, + systemErrors, }) let parsed try { diff --git a/core/base-service/base.js b/core/base-service/base.js index a8c12a9b232ba..776abea4eeb1e 100644 --- a/core/base-service/base.js +++ b/core/base-service/base.js @@ -226,12 +226,7 @@ class BaseService { this._metricHelper = metricHelper } - async _request({ - url, - options = {}, - errorMessages = {}, - customExceptions = {}, - }) { + async _request({ url, options = {}, errorMessages = {}, systemErrors = {} }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) let logUrl = url const logOptions = Object.assign({}, options) @@ -254,7 +249,7 @@ class BaseService { const { res, buffer } = await this._requestFetcher( url, options, - customExceptions + systemErrors ) await this._meterResponse(res, buffer) logTrace(emojic.dart, 'Response status code', res.statusCode) diff --git a/core/base-service/got.js b/core/base-service/got.js index e9b1e1d1ce924..793901e7ea31f 100644 --- a/core/base-service/got.js +++ b/core/base-service/got.js @@ -7,12 +7,7 @@ import { const userAgent = getUserAgent() -async function sendRequest( - gotWrapper, - url, - options = {}, - customExceptions = {} -) { +async function sendRequest(gotWrapper, url, options = {}, systemErrors = {}) { const gotOptions = Object.assign({}, options) gotOptions.throwHttpErrors = false gotOptions.retry = { limit: 0 } @@ -27,9 +22,9 @@ async function sendRequest( underlyingError: new Error('Maximum response size exceeded'), }) } - if (err.code in customExceptions) { + if (err.code in systemErrors) { throw new Inaccessible({ - ...customExceptions[err.code], + ...systemErrors[err.code], underlyingError: err, }) } From b8a184b1012eb320eddbc8c81ecd1538ad6c6567 Mon Sep 17 00:00:00 2001 From: chris48s Date: Mon, 12 Jun 2023 13:07:10 +0100 Subject: [PATCH 6/6] errorMessages --> httpErrors --- core/base-service/base-graphql.js | 2 +- core/base-service/base-json.js | 6 +++--- core/base-service/base-svg-scraping.js | 6 +++--- core/base-service/base-xml.js | 6 +++--- core/base-service/base-yaml.js | 6 +++--- core/base-service/base.js | 4 ++-- core/base-service/check-error-response.js | 10 +++++----- doc/TUTORIAL.md | 4 ++-- doc/service-tests.md | 2 +- services/appveyor/appveyor-base.js | 2 +- services/azure-devops/azure-devops-base.js | 8 ++++---- services/azure-devops/azure-devops-build.service.js | 2 +- .../azure-devops/azure-devops-coverage.service.js | 6 +++--- services/azure-devops/azure-devops-helpers.js | 7 ++----- .../azure-devops/azure-devops-release.service.js | 2 +- services/azure-devops/azure-devops-tests.service.js | 6 +++--- services/bit/bit-components.service.js | 2 +- services/bitbucket/bitbucket-issues.service.js | 2 +- services/bitbucket/bitbucket-pipelines.service.js | 2 +- services/bitbucket/bitbucket-pull-request.service.js | 6 +++--- services/bitrise/bitrise.service.js | 2 +- services/bower/bower-base.js | 2 +- services/bundlephobia/bundlephobia.service.js | 2 +- .../cii-best-practices/cii-best-practices.service.js | 2 +- services/circleci/circleci.service.js | 2 +- .../clearlydefined/clearlydefined-score.service.js | 2 +- services/codacy/codacy-coverage.service.js | 2 +- services/codacy/codacy-grade.service.js | 2 +- services/codecov/codecov.service.js | 4 ++-- services/codefactor/codefactor-grade.service.js | 2 +- services/coincap/coincap-base.js | 2 +- services/coveralls/coveralls.service.js | 2 +- services/coverity/coverity-scan.service.js | 2 +- services/discord/discord.service.js | 2 +- services/docker/docker-automated.service.js | 2 +- services/docker/docker-cloud-common-fetch.js | 2 +- services/docker/docker-pulls.service.js | 2 +- services/docker/docker-size.service.js | 2 +- services/docker/docker-stars.service.js | 2 +- services/docker/docker-version.service.js | 2 +- services/drone/drone-build.service.js | 2 +- services/dynamic-common.js | 4 ++-- services/dynamic/dynamic-json.service.js | 4 ++-- services/dynamic/dynamic-xml.service.js | 4 ++-- services/dynamic/dynamic-yaml.service.js | 4 ++-- services/dynamic/json-path.js | 8 ++++---- .../eclipse-marketplace/eclipse-marketplace-base.js | 2 +- services/ecologi/ecologi-carbon.service.js | 2 +- services/ecologi/ecologi-trees.service.js | 2 +- services/elm-package/elm-package.service.js | 2 +- services/endpoint-common.js | 6 +++--- services/endpoint/endpoint.service.js | 4 ++-- services/f-droid/f-droid.service.js | 2 +- .../factorio-mod-portal.service.js | 2 +- services/fedora/fedora.service.js | 2 +- services/feedz/feedz.service.js | 4 ++-- services/gem/gem-downloads.service.js | 4 ++-- services/gerrit/gerrit.service.js | 2 +- .../github/gist/github-gist-last-commit.service.js | 4 ++-- .../github/github-actions-workflow-status.service.js | 2 +- services/github/github-checks-status.service.js | 4 ++-- services/github/github-commit-status.service.js | 4 ++-- services/github/github-commits-difference.service.js | 4 ++-- services/github/github-commits-since.service.js | 4 ++-- services/github/github-common-fetch.js | 12 ++++++------ services/github/github-common-release.js | 6 +++--- services/github/github-contributors.service.js | 4 ++-- services/github/github-downloads.service.js | 6 +++--- services/github/github-followers.service.js | 4 ++-- services/github/github-helpers.js | 4 ++-- services/github/github-issue-detail.service.js | 4 ++-- services/github/github-labels.service.js | 4 ++-- services/github/github-languages-base.js | 4 ++-- services/github/github-last-commit.service.js | 4 ++-- services/github/github-license.service.js | 4 ++-- services/github/github-milestone-detail.service.js | 4 ++-- services/github/github-milestone.service.js | 4 ++-- .../github-pull-request-check-state.service.js | 4 ++-- services/github/github-release-date.service.js | 4 ++-- services/github/github-repo-size.service.js | 4 ++-- services/github/github-search.service.js | 4 ++-- services/github/github-size.service.js | 6 +++--- services/github/github-stars.service.js | 4 ++-- services/github/github-watchers.service.js | 4 ++-- services/gitlab/gitlab-base.js | 8 ++++---- services/gitlab/gitlab-contributors.service.js | 4 ++-- services/gitlab/gitlab-forks.service.js | 2 +- services/gitlab/gitlab-helper.js | 4 ++-- services/gitlab/gitlab-issues.service.js | 4 ++-- services/gitlab/gitlab-languages-count.service.js | 4 ++-- services/gitlab/gitlab-last-commit.service.js | 4 ++-- services/gitlab/gitlab-license.service.js | 4 ++-- services/gitlab/gitlab-merge-requests.service.js | 4 ++-- services/gitlab/gitlab-pipeline-coverage.service.js | 6 +++--- services/gitlab/gitlab-pipeline-status.service.js | 4 ++-- services/gitlab/gitlab-release.service.js | 4 ++-- services/gitlab/gitlab-stars.service.js | 2 +- services/gitlab/gitlab-tag.service.js | 4 ++-- services/hackernews/hackernews-user-karma.service.js | 2 +- services/homebrew/homebrew-downloads.service.js | 2 +- services/jenkins/jenkins-base.js | 4 ++-- services/jenkins/jenkins-coverage.service.js | 2 +- services/jenkins/jenkins-plugin-installs.service.js | 2 +- services/jetbrains/jetbrains-base.js | 4 ++-- services/jetbrains/jetbrains-downloads.service.js | 2 +- services/jetbrains/jetbrains-rating.service.js | 2 +- services/jetbrains/jetbrains-version.service.js | 2 +- services/jira/jira-issue.service.js | 2 +- services/jira/jira-sprint.service.js | 2 +- services/jitpack/jitpack-version.service.js | 2 +- services/librariesio/librariesio-base.js | 2 +- .../librariesio/librariesio-dependencies.service.js | 4 ++-- services/localizely/localizely.service.js | 2 +- services/luarocks/luarocks.service.js | 2 +- services/matrix/matrix.service.js | 6 +++--- services/nexus/nexus.service.js | 4 ++-- services/npm/npm-base.js | 2 +- services/npm/npm-downloads.service.js | 2 +- services/npm/npm-version.service.js | 2 +- services/npms-io/npms-io-score.service.js | 2 +- services/open-vsx/open-vsx-base.js | 2 +- services/opencollective/opencollective-base.js | 4 ++-- services/opm/opm-version.service.js | 2 +- services/ossf-scorecard/ossf-scorecard.service.js | 2 +- services/piwheels/piwheels-version.service.js | 2 +- services/pypi/pypi-base.js | 2 +- services/pypi/pypi-downloads.service.js | 2 +- services/reddit/subreddit-subscribers.service.js | 2 +- services/reddit/user-karma.service.js | 2 +- services/reuse/reuse-compliance.service.js | 2 +- services/scrutinizer/scrutinizer-base.js | 2 +- services/snyk/snyk-vulnerability-base.js | 4 ++-- services/snyk/snyk-vulnerability-github.service.js | 2 +- services/snyk/snyk-vulnerability-npm.service.js | 2 +- services/sonar/sonar-base.js | 2 +- services/sourceforge/sourceforge-base.js | 2 +- .../sourceforge/sourceforge-commit-count.service.js | 2 +- .../sourceforge/sourceforge-downloads.service.js | 2 +- .../sourceforge/sourceforge-last-commit.service.js | 2 +- .../sourceforge/sourceforge-open-tickets.service.js | 2 +- services/spack/spack.service.js | 2 +- .../stackexchange-reputation.service.js | 2 +- services/steam/steam-base.js | 2 +- services/symfony/symfony-insight-base.js | 2 +- services/tas/tas-tests.service.js | 2 +- services/teamcity/teamcity-base.js | 4 ++-- services/testspace/testspace-base.js | 2 +- services/tokei/tokei.service.js | 2 +- services/twitch/twitch-base.js | 2 +- services/ubuntu/ubuntu.service.js | 2 +- .../visual-studio-app-center-base.js | 2 +- .../visual-studio-marketplace-base.js | 2 +- .../weblate/weblate-component-license.service.js | 2 +- services/weblate/weblate-entities.service.js | 2 +- .../weblate-project-translated-percentage.service.js | 2 +- services/weblate/weblate-user-statistic.service.js | 2 +- services/wheelmap/wheelmap.service.js | 2 +- 157 files changed, 250 insertions(+), 253 deletions(-) diff --git a/core/base-service/base-graphql.js b/core/base-service/base-graphql.js index 646982f2655dc..a81bac29f9c9f 100644 --- a/core/base-service/base-graphql.js +++ b/core/base-service/base-graphql.js @@ -81,7 +81,7 @@ class BaseGraphqlService extends BaseService { const { buffer } = await this._request({ url, options: mergedOptions, - errorMessages: httpErrorMessages, + httpErrors: httpErrorMessages, systemErrors, }) const json = transformJson(this._parseJson(buffer)) diff --git a/core/base-service/base-json.js b/core/base-service/base-json.js index 0a559cf5a2f2b..fe42783bd3276 100644 --- a/core/base-service/base-json.js +++ b/core/base-service/base-json.js @@ -30,7 +30,7 @@ class BaseJsonService extends BaseService { * @param {string} attrs.url URL to request * @param {object} [attrs.options={}] Options to pass to got. See * [documentation](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) - * @param {object} [attrs.errorMessages={}] Key-value map of status codes + * @param {object} [attrs.httpErrors={}] Key-value map of status codes * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) @@ -47,7 +47,7 @@ class BaseJsonService extends BaseService { schema, url, options = {}, - errorMessages = {}, + httpErrors = {}, systemErrors = {}, }) { const mergedOptions = { @@ -57,7 +57,7 @@ class BaseJsonService extends BaseService { const { buffer } = await this._request({ url, options: mergedOptions, - errorMessages, + httpErrors, systemErrors, }) const json = this._parseJson(buffer) diff --git a/core/base-service/base-svg-scraping.js b/core/base-service/base-svg-scraping.js index bc171f18dafd1..95bc3be8ac61f 100644 --- a/core/base-service/base-svg-scraping.js +++ b/core/base-service/base-svg-scraping.js @@ -53,7 +53,7 @@ class BaseSvgScrapingService extends BaseService { * @param {string} attrs.url URL to request * @param {object} [attrs.options={}] Options to pass to got. See * [documentation](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) - * @param {object} [attrs.errorMessages={}] Key-value map of status codes + * @param {object} [attrs.httpErrors={}] Key-value map of status codes * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) @@ -71,7 +71,7 @@ class BaseSvgScrapingService extends BaseService { valueMatcher, url, options = {}, - errorMessages = {}, + httpErrors = {}, systemErrors = {}, }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) @@ -82,7 +82,7 @@ class BaseSvgScrapingService extends BaseService { const { buffer } = await this._request({ url, options: mergedOptions, - errorMessages, + httpErrors, systemErrors, }) logTrace(emojic.dart, 'Response SVG', buffer) diff --git a/core/base-service/base-xml.js b/core/base-service/base-xml.js index 57c0270ea38b9..7395c45ea64bd 100644 --- a/core/base-service/base-xml.js +++ b/core/base-service/base-xml.js @@ -24,7 +24,7 @@ class BaseXmlService extends BaseService { * @param {string} attrs.url URL to request * @param {object} [attrs.options={}] Options to pass to got. See * [documentation](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) - * @param {object} [attrs.errorMessages={}] Key-value map of status codes + * @param {object} [attrs.httpErrors={}] Key-value map of status codes * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) @@ -44,7 +44,7 @@ class BaseXmlService extends BaseService { schema, url, options = {}, - errorMessages = {}, + httpErrors = {}, systemErrors = {}, parserOptions = {}, }) { @@ -56,7 +56,7 @@ class BaseXmlService extends BaseService { const { buffer } = await this._request({ url, options: mergedOptions, - errorMessages, + httpErrors, systemErrors, }) const validateResult = XMLValidator.validate(buffer) diff --git a/core/base-service/base-yaml.js b/core/base-service/base-yaml.js index a17b394aa99d3..bae76068f213f 100644 --- a/core/base-service/base-yaml.js +++ b/core/base-service/base-yaml.js @@ -23,7 +23,7 @@ class BaseYamlService extends BaseService { * @param {string} attrs.url URL to request * @param {object} [attrs.options={}] Options to pass to got. See * [documentation](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) - * @param {object} [attrs.errorMessages={}] Key-value map of status codes + * @param {object} [attrs.httpErrors={}] Key-value map of status codes * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/core/base-service/check-error-response.js#L5) @@ -41,7 +41,7 @@ class BaseYamlService extends BaseService { schema, url, options = {}, - errorMessages = {}, + httpErrors = {}, systemErrors = {}, encoding = 'utf8', }) { @@ -58,7 +58,7 @@ class BaseYamlService extends BaseService { const { buffer } = await this._request({ url, options: mergedOptions, - errorMessages, + httpErrors, systemErrors, }) let parsed diff --git a/core/base-service/base.js b/core/base-service/base.js index 776abea4eeb1e..cf077c562fec9 100644 --- a/core/base-service/base.js +++ b/core/base-service/base.js @@ -226,7 +226,7 @@ class BaseService { this._metricHelper = metricHelper } - async _request({ url, options = {}, errorMessages = {}, systemErrors = {} }) { + async _request({ url, options = {}, httpErrors = {}, systemErrors = {} }) { const logTrace = (...args) => trace.logTrace('fetch', ...args) let logUrl = url const logOptions = Object.assign({}, options) @@ -253,7 +253,7 @@ class BaseService { ) await this._meterResponse(res, buffer) logTrace(emojic.dart, 'Response status code', res.statusCode) - return checkErrorResponse(errorMessages)({ buffer, res }) + return checkErrorResponse(httpErrors)({ buffer, res }) } static enabledMetrics = [] diff --git a/core/base-service/check-error-response.js b/core/base-service/check-error-response.js index 93120d725a9f1..cda53fa7e954b 100644 --- a/core/base-service/check-error-response.js +++ b/core/base-service/check-error-response.js @@ -5,19 +5,19 @@ const defaultErrorMessages = { 429: 'rate limited by upstream service', } -export default function checkErrorResponse(errorMessages = {}) { +export default function checkErrorResponse(httpErrors = {}) { return async function ({ buffer, res }) { let error - errorMessages = { ...defaultErrorMessages, ...errorMessages } + httpErrors = { ...defaultErrorMessages, ...httpErrors } if (res.statusCode === 404) { - error = new NotFound({ prettyMessage: errorMessages[404] }) + error = new NotFound({ prettyMessage: httpErrors[404] }) } else if (res.statusCode !== 200) { const underlying = Error( `Got status code ${res.statusCode} (expected 200)` ) const props = { underlyingError: underlying } - if (errorMessages[res.statusCode] !== undefined) { - props.prettyMessage = errorMessages[res.statusCode] + if (httpErrors[res.statusCode] !== undefined) { + props.prettyMessage = httpErrors[res.statusCode] } if (res.statusCode >= 500) { error = new Inaccessible(props) diff --git a/doc/TUTORIAL.md b/doc/TUTORIAL.md index 06441df876195..f649f197ce5f9 100644 --- a/doc/TUTORIAL.md +++ b/doc/TUTORIAL.md @@ -229,14 +229,14 @@ Description of the code: - `_requestJson()` automatically adds an Accept header, checks the status code, parses the response as JSON, and returns the parsed response. - `_requestJson()` uses [got](https://github.com/sindresorhus/got) to perform the HTTP request. Options can be passed to got, including method, query string, and headers. If headers are provided they will override the ones automatically set by `_requestJson()`. There is no need to specify json, as the JSON parsing is handled by `_requestJson()`. See the `got` docs for [supported options](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md). - - Error messages corresponding to each status code can be returned by passing a dictionary of status codes -> messages in `errorMessages`. + - Error messages corresponding to each status code can be returned by passing a dictionary of status codes -> messages in `httpErrors`. - A more complex call to `_requestJson()` might look like this: ```js return this._requestJson({ schema: mySchema, url, options: { searchParams: { branch: 'master' } }, - errorMessages: { + httpErrors: { 401: 'private application not supported', 404: 'application not found', }, diff --git a/doc/service-tests.md b/doc/service-tests.md index 2242920f685f5..45f5cd81633ca 100644 --- a/doc/service-tests.md +++ b/doc/service-tests.md @@ -152,7 +152,7 @@ npm run test:services -- --only="wercker" --fgrep="Build status (with branch)" Having covered the typical and custom cases, we'll move on to errors. We should include a test for the 'not found' response and also tests for any other custom error handling. The Wercker integration defines a custom error condition for 401 as well as a custom 404 message: ```js -errorMessages: { +httpErrors: { 401: 'private application not supported', 404: 'application not found', } diff --git a/services/appveyor/appveyor-base.js b/services/appveyor/appveyor-base.js index 923b718466cbf..9903beae5fafa 100644 --- a/services/appveyor/appveyor-base.js +++ b/services/appveyor/appveyor-base.js @@ -29,7 +29,7 @@ export default class AppVeyorBase extends BaseJsonService { return this._requestJson({ schema, url, - errorMessages: { 404: 'project not found or access denied' }, + httpErrors: { 404: 'project not found or access denied' }, }) } diff --git a/services/azure-devops/azure-devops-base.js b/services/azure-devops/azure-devops-base.js index 6b01bea8466d2..85331836d49dd 100644 --- a/services/azure-devops/azure-devops-base.js +++ b/services/azure-devops/azure-devops-base.js @@ -19,13 +19,13 @@ export default class AzureDevOpsBase extends BaseJsonService { defaultToEmptyStringForUser: true, } - async fetch({ url, options, schema, errorMessages }) { + async fetch({ url, options, schema, httpErrors }) { return this._requestJson( this.authHelper.withBasicAuth({ schema, url, options, - errorMessages, + httpErrors, }) ) } @@ -35,7 +35,7 @@ export default class AzureDevOpsBase extends BaseJsonService { project, definitionId, branch, - errorMessages + httpErrors ) { // Microsoft documentation: https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-5.0 const url = `https://dev.azure.com/${organization}/${project}/_apis/build/builds` @@ -56,7 +56,7 @@ export default class AzureDevOpsBase extends BaseJsonService { url, options, schema: latestBuildSchema, - errorMessages, + httpErrors, }) if (json.count !== 1) { diff --git a/services/azure-devops/azure-devops-build.service.js b/services/azure-devops/azure-devops-build.service.js index a4c2bc93b702d..98403df403711 100644 --- a/services/azure-devops/azure-devops-build.service.js +++ b/services/azure-devops/azure-devops-build.service.js @@ -109,7 +109,7 @@ export default class AzureDevOpsBuild extends BaseSvgScrapingService { stageName: stage, jobName: job, }, - errorMessages: { + httpErrors: { 404: 'user or project not found', }, }) diff --git a/services/azure-devops/azure-devops-coverage.service.js b/services/azure-devops/azure-devops-coverage.service.js index eb5b7eeb797c1..6ab0ad9fe0225 100644 --- a/services/azure-devops/azure-devops-coverage.service.js +++ b/services/azure-devops/azure-devops-coverage.service.js @@ -88,7 +88,7 @@ export default class AzureDevOpsCoverage extends AzureDevOpsBase { } async handle({ organization, project, definitionId, branch }) { - const errorMessages = { + const httpErrors = { 404: 'build pipeline or coverage not found', } const buildId = await this.getLatestCompletedBuildId( @@ -96,7 +96,7 @@ export default class AzureDevOpsCoverage extends AzureDevOpsBase { project, definitionId, branch, - errorMessages + httpErrors ) // Microsoft documentation: https://docs.microsoft.com/en-us/rest/api/azure/devops/test/code%20coverage/get%20build%20code%20coverage?view=azure-devops-rest-5.0 const url = `https://dev.azure.com/${organization}/${project}/_apis/test/codecoverage` @@ -110,7 +110,7 @@ export default class AzureDevOpsCoverage extends AzureDevOpsBase { url, options, schema: buildCodeCoverageSchema, - errorMessages, + httpErrors, }) let covered = 0 diff --git a/services/azure-devops/azure-devops-helpers.js b/services/azure-devops/azure-devops-helpers.js index e57f8c8347232..a2a0c89694d4d 100644 --- a/services/azure-devops/azure-devops-helpers.js +++ b/services/azure-devops/azure-devops-helpers.js @@ -15,16 +15,13 @@ const schema = Joi.object({ .required(), }).required() -async function fetch( - serviceInstance, - { url, searchParams = {}, errorMessages } -) { +async function fetch(serviceInstance, { url, searchParams = {}, httpErrors }) { // Microsoft documentation: https://docs.microsoft.com/en-us/rest/api/vsts/build/status/get const { message: status } = await serviceInstance._requestSvg({ schema, url, options: { searchParams }, - errorMessages, + httpErrors, }) return { status } } diff --git a/services/azure-devops/azure-devops-release.service.js b/services/azure-devops/azure-devops-release.service.js index 96393ad4b0d94..288f62435d1cf 100644 --- a/services/azure-devops/azure-devops-release.service.js +++ b/services/azure-devops/azure-devops-release.service.js @@ -49,7 +49,7 @@ export default class AzureDevOpsRelease extends BaseSvgScrapingService { // Microsoft documentation: ? const props = await fetch(this, { url: `https://vsrm.dev.azure.com/${organization}/_apis/public/Release/badge/${projectId}/${definitionId}/${environmentId}`, - errorMessages: { + httpErrors: { 400: 'project not found', 404: 'user or environment not found', 500: 'inaccessible or definition not found', diff --git a/services/azure-devops/azure-devops-tests.service.js b/services/azure-devops/azure-devops-tests.service.js index 8b10ebf4318f0..e27b505f55b7b 100644 --- a/services/azure-devops/azure-devops-tests.service.js +++ b/services/azure-devops/azure-devops-tests.service.js @@ -145,7 +145,7 @@ export default class AzureDevOpsTests extends AzureDevOpsBase { } async fetchTestResults({ organization, project, definitionId, branch }) { - const errorMessages = { + const httpErrors = { 404: 'build pipeline or test result summary not found', } const buildId = await this.getLatestCompletedBuildId( @@ -153,7 +153,7 @@ export default class AzureDevOpsTests extends AzureDevOpsBase { project, definitionId, branch, - errorMessages + httpErrors ) // https://dev.azure.com/azuredevops-powershell/azuredevops-powershell/_apis/test/ResultSummaryByBuild?buildId=20 @@ -163,7 +163,7 @@ export default class AzureDevOpsTests extends AzureDevOpsBase { searchParams: { buildId }, }, schema: buildTestResultSummarySchema, - errorMessages, + httpErrors, }) } diff --git a/services/bit/bit-components.service.js b/services/bit/bit-components.service.js index e2236639034b7..15f27730d4dfc 100644 --- a/services/bit/bit-components.service.js +++ b/services/bit/bit-components.service.js @@ -37,7 +37,7 @@ export default class BitComponents extends BaseJsonService { return this._requestJson({ url, schema: collectionSchema, - errorMessages: { + httpErrors: { 404: 'collection not found', }, }) diff --git a/services/bitbucket/bitbucket-issues.service.js b/services/bitbucket/bitbucket-issues.service.js index 38eafea3a3d5a..2da5a629cd224 100644 --- a/services/bitbucket/bitbucket-issues.service.js +++ b/services/bitbucket/bitbucket-issues.service.js @@ -46,7 +46,7 @@ function issueClassGenerator(raw) { options: { searchParams: { limit: 0, q: '(state = "new" OR state = "open")' }, }, - errorMessages: { 403: 'private repo' }, + httpErrors: { 403: 'private repo' }, }) } diff --git a/services/bitbucket/bitbucket-pipelines.service.js b/services/bitbucket/bitbucket-pipelines.service.js index 29d0277d4b58c..878a518a3b229 100644 --- a/services/bitbucket/bitbucket-pipelines.service.js +++ b/services/bitbucket/bitbucket-pipelines.service.js @@ -63,7 +63,7 @@ class BitbucketPipelines extends BaseJsonService { 'target.ref_name': branch, }, }, - errorMessages: { 403: 'private repo' }, + httpErrors: { 403: 'private repo' }, }) } diff --git a/services/bitbucket/bitbucket-pull-request.service.js b/services/bitbucket/bitbucket-pull-request.service.js index b885109fb5736..9606e8213885a 100644 --- a/services/bitbucket/bitbucket-pull-request.service.js +++ b/services/bitbucket/bitbucket-pull-request.service.js @@ -12,7 +12,7 @@ const queryParamSchema = Joi.object({ server: optionalUrl, }).required() -const errorMessages = { +const httpErrors = { 401: 'invalid credentials', 403: 'private repo', 404: 'not found', @@ -87,7 +87,7 @@ function pullRequestClassGenerator(raw) { url: `https://bitbucket.org/api/2.0/repositories/${user}/${repo}/pullrequests/`, schema, options: { searchParams: { state: 'OPEN', limit: 0 } }, - errorMessages, + httpErrors, }) ) } @@ -106,7 +106,7 @@ function pullRequestClassGenerator(raw) { withAttributes: false, }, }, - errorMessages, + httpErrors, }) ) } diff --git a/services/bitrise/bitrise.service.js b/services/bitrise/bitrise.service.js index cca2a786669d3..49e5f2fb901c6 100644 --- a/services/bitrise/bitrise.service.js +++ b/services/bitrise/bitrise.service.js @@ -55,7 +55,7 @@ export default class Bitrise extends BaseJsonService { )}/status.json`, options: { searchParams: { token, branch } }, schema, - errorMessages: { + httpErrors: { 403: 'app not found or invalid token', }, }) diff --git a/services/bower/bower-base.js b/services/bower/bower-base.js index 92fb2c1e26225..2ead07514aab5 100644 --- a/services/bower/bower-base.js +++ b/services/bower/bower-base.js @@ -22,7 +22,7 @@ export default class BaseBowerService extends LibrariesIoBase { return this._requestJson({ schema, url: `/bower/${packageName}`, - errorMessages: { + httpErrors: { 404: 'package not found', }, }) diff --git a/services/bundlephobia/bundlephobia.service.js b/services/bundlephobia/bundlephobia.service.js index c3fed6cdd1134..68ac512620900 100644 --- a/services/bundlephobia/bundlephobia.service.js +++ b/services/bundlephobia/bundlephobia.service.js @@ -84,7 +84,7 @@ export default class Bundlephobia extends BaseJsonService { schema, url: 'https://bundlephobia.com/api/size', options, - errorMessages: { + httpErrors: { 404: 'package or version not found', }, }) diff --git a/services/cii-best-practices/cii-best-practices.service.js b/services/cii-best-practices/cii-best-practices.service.js index d7230334dd3ea..2ee81cec50a63 100644 --- a/services/cii-best-practices/cii-best-practices.service.js +++ b/services/cii-best-practices/cii-best-practices.service.js @@ -115,7 +115,7 @@ export default class CIIBestPracticesService extends BaseJsonService { await this._requestJson({ schema, url: `https://bestpractices.coreinfrastructure.org/projects/${projectId}/badge.json`, - errorMessages: { + httpErrors: { 404: 'project not found', }, }) diff --git a/services/circleci/circleci.service.js b/services/circleci/circleci.service.js index 11dd943cd3cf1..49ca87d5d07eb 100644 --- a/services/circleci/circleci.service.js +++ b/services/circleci/circleci.service.js @@ -57,7 +57,7 @@ class CircleCi extends BaseSvgScrapingService { // Note that the unusual 'circle-token' query param name is required. // https://circleci.com/docs/api/#get-authenticated options: { searchParams: { style: 'shield', 'circle-token': token } }, - errorMessages: { 404: 'project not found' }, + httpErrors: { 404: 'project not found' }, }) return this.constructor.render({ status: message }) } diff --git a/services/clearlydefined/clearlydefined-score.service.js b/services/clearlydefined/clearlydefined-score.service.js index f480581af6479..d100df5bcca76 100644 --- a/services/clearlydefined/clearlydefined-score.service.js +++ b/services/clearlydefined/clearlydefined-score.service.js @@ -53,7 +53,7 @@ export default class ClearlyDefinedService extends BaseJsonService { return this._requestJson({ schema, url: `https://api.clearlydefined.io/definitions/${type}/${provider}/${namespace}/${name}/${revision}`, - errorMessages: { + httpErrors: { 500: 'unknown type, provider, or upstream issue', }, }) diff --git a/services/codacy/codacy-coverage.service.js b/services/codacy/codacy-coverage.service.js index d57c1e80e3224..7deae5d34d089 100644 --- a/services/codacy/codacy-coverage.service.js +++ b/services/codacy/codacy-coverage.service.js @@ -53,7 +53,7 @@ export default class CodacyCoverage extends BaseSvgScrapingService { )}`, options: { searchParams: { branch } }, valueMatcher: /text-anchor="middle">([^<>]+)<\/text>/, - errorMessages: { + httpErrors: { 404: 'project not found', }, }) diff --git a/services/codacy/codacy-grade.service.js b/services/codacy/codacy-grade.service.js index aeee96579cfce..afb4ccabcc42a 100644 --- a/services/codacy/codacy-grade.service.js +++ b/services/codacy/codacy-grade.service.js @@ -51,7 +51,7 @@ export default class CodacyGrade extends BaseSvgScrapingService { projectId )}`, options: { searchParams: { branch } }, - errorMessages: { 404: 'project or branch not found' }, + httpErrors: { 404: 'project or branch not found' }, valueMatcher: /visibility="hidden">([^<>]+)<\/text>/, }) return this.constructor.render({ grade }) diff --git a/services/codecov/codecov.service.js b/services/codecov/codecov.service.js index d6ab261498eaf..6c505854ba181 100644 --- a/services/codecov/codecov.service.js +++ b/services/codecov/codecov.service.js @@ -117,7 +117,7 @@ export default class Codecov extends BaseSvgScrapingService { Authorization: `token ${token}`, }, }, - errorMessages: { + httpErrors: { 401: 'not authorized to access repository', 404: 'repository not found', }, @@ -153,7 +153,7 @@ export default class Codecov extends BaseSvgScrapingService { options: { searchParams: { token, flag }, }, - errorMessages: token ? { 400: 'invalid token pattern' } : {}, + httpErrors: token ? { 400: 'invalid token pattern' } : {}, }) } diff --git a/services/codefactor/codefactor-grade.service.js b/services/codefactor/codefactor-grade.service.js index 70528574be46d..0752654565fca 100644 --- a/services/codefactor/codefactor-grade.service.js +++ b/services/codefactor/codefactor-grade.service.js @@ -41,7 +41,7 @@ export default class CodeFactorGrade extends BaseSvgScrapingService { url: `https://codefactor.io/repository/${vcsType}/${user}/${repo}/badge/${ branch || '' }`, - errorMessages: { 404: 'repo or branch not found' }, + httpErrors: { 404: 'repo or branch not found' }, }) return this.constructor.render({ grade: message }) } diff --git a/services/coincap/coincap-base.js b/services/coincap/coincap-base.js index 7ad3dfb6c6f2f..d602fb252954e 100644 --- a/services/coincap/coincap-base.js +++ b/services/coincap/coincap-base.js @@ -12,7 +12,7 @@ export default class BaseCoincapService extends BaseJsonService { return this._requestJson({ schema, url: `https://api.coincap.io/v2/assets/${assetId}`, - errorMessages: { + httpErrors: { 404: 'asset not found', }, }) diff --git a/services/coveralls/coveralls.service.js b/services/coveralls/coveralls.service.js index 9f20c419be0c8..1b2b412f35d8a 100644 --- a/services/coveralls/coveralls.service.js +++ b/services/coveralls/coveralls.service.js @@ -66,7 +66,7 @@ export default class Coveralls extends BaseJsonService { schema, url, options, - errorMessages: { + httpErrors: { 404: 'repository not found', }, }) diff --git a/services/coverity/coverity-scan.service.js b/services/coverity/coverity-scan.service.js index 2c1e9362362f3..7f6a74210b66a 100644 --- a/services/coverity/coverity-scan.service.js +++ b/services/coverity/coverity-scan.service.js @@ -48,7 +48,7 @@ export default class CoverityScan extends BaseJsonService { const json = await this._requestJson({ url, schema, - errorMessages: { + httpErrors: { // At the moment Coverity returns an HTTP 200 with an HTML page // displaying the text 404 when project is not found. 404: 'project not found', diff --git a/services/discord/discord.service.js b/services/discord/discord.service.js index 65837b9a35004..5fe8944be119d 100644 --- a/services/discord/discord.service.js +++ b/services/discord/discord.service.js @@ -63,7 +63,7 @@ export default class Discord extends BaseJsonService { { url, schema, - errorMessages: { + httpErrors: { 404: 'invalid server', 403: 'widget disabled', }, diff --git a/services/docker/docker-automated.service.js b/services/docker/docker-automated.service.js index ba28af2990520..c5432f8134394 100644 --- a/services/docker/docker-automated.service.js +++ b/services/docker/docker-automated.service.js @@ -40,7 +40,7 @@ export default class DockerAutomatedBuild extends BaseJsonService { url: `https://registry.hub.docker.com/v2/repositories/${getDockerHubUser( user )}/${repo}`, - errorMessages: { 404: 'repo not found' }, + httpErrors: { 404: 'repo not found' }, }) } diff --git a/services/docker/docker-cloud-common-fetch.js b/services/docker/docker-cloud-common-fetch.js index 51d763261e248..bea59e66d3e50 100644 --- a/services/docker/docker-cloud-common-fetch.js +++ b/services/docker/docker-cloud-common-fetch.js @@ -16,7 +16,7 @@ async function fetchBuild(serviceInstance, { user, repo }) { schema: cloudBuildSchema, url: 'https://cloud.docker.com/api/build/v1/source', options: { searchParams: { image: `${user}/${repo}` } }, - errorMessages: { 404: 'repo not found' }, + httpErrors: { 404: 'repo not found' }, }) } diff --git a/services/docker/docker-pulls.service.js b/services/docker/docker-pulls.service.js index 4a31a16843b94..e1a8e8a129c42 100644 --- a/services/docker/docker-pulls.service.js +++ b/services/docker/docker-pulls.service.js @@ -38,7 +38,7 @@ export default class DockerPulls extends BaseJsonService { url: `https://hub.docker.com/v2/repositories/${getDockerHubUser( user )}/${repo}`, - errorMessages: { 404: 'repo not found' }, + httpErrors: { 404: 'repo not found' }, }) } diff --git a/services/docker/docker-size.service.js b/services/docker/docker-size.service.js index 4d4c5f6a6a11e..bef483105c86a 100644 --- a/services/docker/docker-size.service.js +++ b/services/docker/docker-size.service.js @@ -107,7 +107,7 @@ export default class DockerSize extends BaseJsonService { )}/${repo}/tags${ tag ? `/${tag}` : '?page_size=100&ordering=last_updated' }${page}`, - errorMessages: { 404: 'repository or tag not found' }, + httpErrors: { 404: 'repository or tag not found' }, }) } diff --git a/services/docker/docker-stars.service.js b/services/docker/docker-stars.service.js index f7e645aba19df..49a43e5d61cff 100644 --- a/services/docker/docker-stars.service.js +++ b/services/docker/docker-stars.service.js @@ -41,7 +41,7 @@ export default class DockerStars extends BaseJsonService { url: `https://hub.docker.com/v2/repositories/${getDockerHubUser( user )}/${repo}/`, - errorMessages: { 404: 'repo not found' }, + httpErrors: { 404: 'repo not found' }, }) } diff --git a/services/docker/docker-version.service.js b/services/docker/docker-version.service.js index 594c8e9647793..e61ff42a423ad 100644 --- a/services/docker/docker-version.service.js +++ b/services/docker/docker-version.service.js @@ -69,7 +69,7 @@ export default class DockerVersion extends BaseJsonService { url: `https://registry.hub.docker.com/v2/repositories/${getDockerHubUser( user )}/${repo}/tags?page_size=100&ordering=last_updated${page}`, - errorMessages: { 404: 'repository or tag not found' }, + httpErrors: { 404: 'repository or tag not found' }, }) } diff --git a/services/drone/drone-build.service.js b/services/drone/drone-build.service.js index 3951fd84da3bd..74132b6046717 100644 --- a/services/drone/drone-build.service.js +++ b/services/drone/drone-build.service.js @@ -75,7 +75,7 @@ export default class DroneBuild extends BaseJsonService { options: { searchParams: { ref: branch ? `refs/heads/${branch}` : undefined }, }, - errorMessages: { + httpErrors: { 401: 'repo not found or not authorized', }, }) diff --git a/services/dynamic-common.js b/services/dynamic-common.js index d82faaf81127c..04a68e78cd301 100644 --- a/services/dynamic-common.js +++ b/services/dynamic-common.js @@ -14,7 +14,7 @@ import { InvalidResponse } from './index.js' * * @type {object} */ -const errorMessages = { +const httpErrors = { 404: 'resource not found', } @@ -93,7 +93,7 @@ function renderDynamicBadge({ } export { - errorMessages, + httpErrors, individualValueSchema, transformAndValidate, renderDynamicBadge, diff --git a/services/dynamic/dynamic-json.service.js b/services/dynamic/dynamic-json.service.js index 0dc3fa56a8798..68ffd4f6dc54d 100644 --- a/services/dynamic/dynamic-json.service.js +++ b/services/dynamic/dynamic-json.service.js @@ -54,11 +54,11 @@ export default class DynamicJson extends jsonPath(BaseJsonService) { }, } - async fetch({ schema, url, errorMessages }) { + async fetch({ schema, url, httpErrors }) { return this._requestJson({ schema, url, - errorMessages, + httpErrors, }) } } diff --git a/services/dynamic/dynamic-xml.service.js b/services/dynamic/dynamic-xml.service.js index 3426af989bfa3..fd4216c5a0302 100644 --- a/services/dynamic/dynamic-xml.service.js +++ b/services/dynamic/dynamic-xml.service.js @@ -1,7 +1,7 @@ import { DOMParser } from '@xmldom/xmldom' import xpath from 'xpath' import { MetricNames } from '../../core/base-service/metric-helper.js' -import { renderDynamicBadge, errorMessages } from '../dynamic-common.js' +import { renderDynamicBadge, httpErrors } from '../dynamic-common.js' import { BaseService, InvalidResponse, InvalidParameter } from '../index.js' import { createRoute } from './dynamic-helpers.js' @@ -113,7 +113,7 @@ export default class DynamicXml extends BaseService { const { buffer } = await this._request({ url, options: { headers: { Accept: 'application/xml, text/xml' } }, - errorMessages, + httpErrors, }) const { values: value } = this.transform({ diff --git a/services/dynamic/dynamic-yaml.service.js b/services/dynamic/dynamic-yaml.service.js index 46f84dd8e08b3..c1a5ab29ce229 100644 --- a/services/dynamic/dynamic-yaml.service.js +++ b/services/dynamic/dynamic-yaml.service.js @@ -54,11 +54,11 @@ export default class DynamicYaml extends jsonPath(BaseYamlService) { }, } - async fetch({ schema, url, errorMessages }) { + async fetch({ schema, url, httpErrors }) { return this._requestYaml({ schema, url, - errorMessages, + httpErrors, }) } } diff --git a/services/dynamic/json-path.js b/services/dynamic/json-path.js index ed242c944aaf4..64c45d1578519 100644 --- a/services/dynamic/json-path.js +++ b/services/dynamic/json-path.js @@ -4,7 +4,7 @@ import Joi from 'joi' import jp from 'jsonpath' -import { renderDynamicBadge, errorMessages } from '../dynamic-common.js' +import { renderDynamicBadge, httpErrors } from '../dynamic-common.js' import { InvalidParameter, InvalidResponse } from '../index.js' /** @@ -24,13 +24,13 @@ export default superclass => * @param {object} attrs Refer to individual attrs * @param {Joi} attrs.schema Joi schema to validate the response transformed to JSON * @param {string} attrs.url URL to request - * @param {object} [attrs.errorMessages={}] Key-value map of status codes + * @param {object} [attrs.httpErrors={}] Key-value map of status codes * and custom error messages e.g: `{ 404: 'package not found' }`. * This can be used to extend or override the * [default](https://github.com/badges/shields/blob/master/services/dynamic-common.js#L8) * @returns {object} Parsed response */ - async fetch({ schema, url, errorMessages }) { + async fetch({ schema, url, httpErrors }) { throw new Error( `fetch() function not implemented for ${this.constructor.name}` ) @@ -40,7 +40,7 @@ export default superclass => const data = await this.fetch({ schema: Joi.any(), url, - errorMessages, + httpErrors, }) // JSONPath only works on objects and arrays. diff --git a/services/eclipse-marketplace/eclipse-marketplace-base.js b/services/eclipse-marketplace/eclipse-marketplace-base.js index a4276731b9582..2324219ef23b2 100644 --- a/services/eclipse-marketplace/eclipse-marketplace-base.js +++ b/services/eclipse-marketplace/eclipse-marketplace-base.js @@ -12,7 +12,7 @@ export default class EclipseMarketplaceBase extends BaseXmlService { return this._requestXml({ schema, url: `https://marketplace.eclipse.org/content/${name}/api/p`, - errorMessages: { 404: 'solution not found' }, + httpErrors: { 404: 'solution not found' }, }) } } diff --git a/services/ecologi/ecologi-carbon.service.js b/services/ecologi/ecologi-carbon.service.js index 4aac425d1e608..01d878780fe63 100644 --- a/services/ecologi/ecologi-carbon.service.js +++ b/services/ecologi/ecologi-carbon.service.js @@ -30,7 +30,7 @@ export default class EcologiCarbonOffset extends BaseJsonService { return this._requestJson({ url, schema: apiSchema, - errorMessages: { + httpErrors: { 404: 'username not found', }, }) diff --git a/services/ecologi/ecologi-trees.service.js b/services/ecologi/ecologi-trees.service.js index 46d41b2f00f19..0d4225bb17c1c 100644 --- a/services/ecologi/ecologi-trees.service.js +++ b/services/ecologi/ecologi-trees.service.js @@ -30,7 +30,7 @@ export default class EcologiTrees extends BaseJsonService { return this._requestJson({ url, schema: apiSchema, - errorMessages: { + httpErrors: { 404: 'username not found', }, }) diff --git a/services/elm-package/elm-package.service.js b/services/elm-package/elm-package.service.js index dd606d090c0ff..cf608fd5971e2 100644 --- a/services/elm-package/elm-package.service.js +++ b/services/elm-package/elm-package.service.js @@ -27,7 +27,7 @@ export default class ElmPackage extends BaseJsonService { const { version } = await this._requestJson({ schema, url, - errorMessages: { + httpErrors: { 404: 'package not found', }, }) diff --git a/services/endpoint-common.js b/services/endpoint-common.js index 5b5c99828109c..164762fd82b30 100644 --- a/services/endpoint-common.js +++ b/services/endpoint-common.js @@ -82,19 +82,19 @@ const anySchema = Joi.any() * @param {object} serviceInstance Instance of Endpoint class * @param {object} attrs Refer to individual attributes * @param {string} attrs.url Endpoint URL - * @param {object} attrs.errorMessages Object containing error messages for different error codes + * @param {object} attrs.httpErrors Object containing error messages for different error codes * @param {string} attrs.validationPrettyErrorMessage If provided then the error message is set to this value * @param {boolean} attrs.includeKeys If true then includes error details in error message * @returns {object} Data fetched from endpoint */ async function fetchEndpointData( serviceInstance, - { url, errorMessages, validationPrettyErrorMessage, includeKeys } + { url, httpErrors, validationPrettyErrorMessage, includeKeys } ) { const json = await serviceInstance._requestJson({ schema: anySchema, url, - errorMessages, + httpErrors, options: { decompress: true }, }) return validateEndpointData(json, { diff --git a/services/endpoint/endpoint.service.js b/services/endpoint/endpoint.service.js index 4a33259df29a7..10fc4e0174874 100644 --- a/services/endpoint/endpoint.service.js +++ b/services/endpoint/endpoint.service.js @@ -1,6 +1,6 @@ import { URL } from 'url' import Joi from 'joi' -import { errorMessages } from '../dynamic-common.js' +import { httpErrors } from '../dynamic-common.js' import { optionalUrl } from '../validators.js' import { fetchEndpointData } from '../endpoint-common.js' import { BaseJsonService, InvalidParameter } from '../index.js' @@ -203,7 +203,7 @@ export default class Endpoint extends BaseJsonService { const validated = await fetchEndpointData(this, { url, - errorMessages, + httpErrors, validationPrettyErrorMessage: 'invalid properties', includeKeys: true, }) diff --git a/services/f-droid/f-droid.service.js b/services/f-droid/f-droid.service.js index 3ce765eb202c2..33de691533692 100644 --- a/services/f-droid/f-droid.service.js +++ b/services/f-droid/f-droid.service.js @@ -53,7 +53,7 @@ export default class FDroid extends BaseJsonService { return this._requestJson({ schema, url, - errorMessages: { + httpErrors: { 403: 'app not found', 404: 'app not found', }, diff --git a/services/factorio-mod-portal/factorio-mod-portal.service.js b/services/factorio-mod-portal/factorio-mod-portal.service.js index 27217d267eb8e..904a7f4a6804a 100644 --- a/services/factorio-mod-portal/factorio-mod-portal.service.js +++ b/services/factorio-mod-portal/factorio-mod-portal.service.js @@ -29,7 +29,7 @@ class BaseFactorioModPortalService extends BaseJsonService { const { releases, downloads_count } = await this._requestJson({ schema, url: `https://mods.factorio.com/api/mods/${modName}`, - errorMessages: { + httpErrors: { 404: 'mod not found', }, }) diff --git a/services/fedora/fedora.service.js b/services/fedora/fedora.service.js index d869bcd6efef1..10c7ee0163cac 100644 --- a/services/fedora/fedora.service.js +++ b/services/fedora/fedora.service.js @@ -30,7 +30,7 @@ export default class Fedora extends BaseJsonService { url: `https://apps.fedoraproject.org/mdapi/${encodeURIComponent( branch )}/pkg/${encodeURIComponent(packageName)}`, - errorMessages: { + httpErrors: { 400: 'branch not found', }, }) diff --git a/services/feedz/feedz.service.js b/services/feedz/feedz.service.js index 9039f1bf9afec..8bd2309194c9c 100644 --- a/services/feedz/feedz.service.js +++ b/services/feedz/feedz.service.js @@ -75,7 +75,7 @@ class FeedzVersionService extends BaseJsonService { return await this._requestJson({ schema: packageSchema, url: `${registrationsBaseUrl}${packageName}/index.json`, - errorMessages: { + httpErrors: { 404: 'repository or package not found', }, }) @@ -90,7 +90,7 @@ class FeedzVersionService extends BaseJsonService { this._requestJson({ schema: singlePageSchema, url: i['@id'], - errorMessages: { + httpErrors: { 404: 'repository or package not found', }, }) diff --git a/services/gem/gem-downloads.service.js b/services/gem/gem-downloads.service.js index 6028530a2455f..6944fe406beab 100644 --- a/services/gem/gem-downloads.service.js +++ b/services/gem/gem-downloads.service.js @@ -88,7 +88,7 @@ export default class GemDownloads extends BaseJsonService { const json = await this._requestJson({ url: `https://rubygems.org/api/v1/versions/${gem}.json`, schema: versionSchema, - errorMessages: { + httpErrors: { 404: 'gem not found', }, }) @@ -117,7 +117,7 @@ export default class GemDownloads extends BaseJsonService { await this._requestJson({ url: `https://rubygems.org/api/v1/gems/${gem}.json`, schema: gemSchema, - errorMessages: { + httpErrors: { 404: 'gem not found', }, }) diff --git a/services/gerrit/gerrit.service.js b/services/gerrit/gerrit.service.js index 04ebca37578d2..b6271d588a9ae 100644 --- a/services/gerrit/gerrit.service.js +++ b/services/gerrit/gerrit.service.js @@ -64,7 +64,7 @@ export default class Gerrit extends BaseJsonService { return this._requestJson({ schema, url: `${baseUrl}/changes/${changeId}`, - errorMessages: { + httpErrors: { 404: 'change not found', }, }) diff --git a/services/github/gist/github-gist-last-commit.service.js b/services/github/gist/github-gist-last-commit.service.js index cc148a8550f16..db5c8089cd985 100644 --- a/services/github/gist/github-gist-last-commit.service.js +++ b/services/github/gist/github-gist-last-commit.service.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { formatDate } from '../../text-formatters.js' import { age as ageColor } from '../../color-formatters.js' import { GithubAuthV3Service } from '../github-auth-service.js' -import { documentation, errorMessagesFor } from '../github-helpers.js' +import { documentation, httpErrorsFor } from '../github-helpers.js' const schema = Joi.object({ updated_at: Joi.string().required(), @@ -36,7 +36,7 @@ export default class GistLastCommit extends GithubAuthV3Service { return this._requestJson({ url: `/gists/${gistId}`, schema, - errorMessages: errorMessagesFor('gist not found'), + httpErrors: httpErrorsFor('gist not found'), }) } diff --git a/services/github/github-actions-workflow-status.service.js b/services/github/github-actions-workflow-status.service.js index 2c598cc3f5801..e3f757fcc6218 100644 --- a/services/github/github-actions-workflow-status.service.js +++ b/services/github/github-actions-workflow-status.service.js @@ -85,7 +85,7 @@ export default class GithubActionsWorkflowStatus extends BaseSvgScrapingService )}/badge.svg`, options: { searchParams: { branch, event } }, valueMatcher: />([^<>]+)<\/tspan><\/text><\/g> ` -function errorMessagesFor(notFoundMessage = 'project not found') { +function httpErrorsFor(notFoundMessage = 'project not found') { return { 401: notFoundMessage, 404: notFoundMessage, } } -export { documentation, errorMessagesFor } +export { documentation, httpErrorsFor } diff --git a/services/gitlab/gitlab-issues.service.js b/services/gitlab/gitlab-issues.service.js index ad86069f95565..3f88d66519c42 100644 --- a/services/gitlab/gitlab-issues.service.js +++ b/services/gitlab/gitlab-issues.service.js @@ -1,7 +1,7 @@ import Joi from 'joi' import { optionalUrl, nonNegativeInteger } from '../validators.js' import { metric } from '../text-formatters.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' const schema = Joi.object({ @@ -237,7 +237,7 @@ export default class GitlabIssues extends GitLabBase { project )}/issues_statistics`, options: labels ? { searchParams: { labels } } : undefined, - errorMessages: errorMessagesFor('project not found'), + httpErrors: httpErrorsFor('project not found'), }) } diff --git a/services/gitlab/gitlab-languages-count.service.js b/services/gitlab/gitlab-languages-count.service.js index 60e6588e7a457..4d08f13b6786a 100644 --- a/services/gitlab/gitlab-languages-count.service.js +++ b/services/gitlab/gitlab-languages-count.service.js @@ -1,7 +1,7 @@ import Joi from 'joi' import { optionalUrl } from '../validators.js' import { metric } from '../text-formatters.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' /* @@ -54,7 +54,7 @@ export default class GitlabLanguageCount extends GitLabBase { url: `${baseUrl}/api/v4/projects/${encodeURIComponent( project )}/languages`, - errorMessages: errorMessagesFor('project not found'), + httpErrors: httpErrorsFor('project not found'), }) } diff --git a/services/gitlab/gitlab-last-commit.service.js b/services/gitlab/gitlab-last-commit.service.js index b2342d669b0fe..c69050dfe47d4 100644 --- a/services/gitlab/gitlab-last-commit.service.js +++ b/services/gitlab/gitlab-last-commit.service.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { optionalUrl } from '../validators.js' import { formatDate } from '../text-formatters.js' import { age as ageColor } from '../color-formatters.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' const schema = Joi.array() @@ -65,7 +65,7 @@ export default class GitlabLastCommit extends GitLabBase { )}/repository/commits`, options: { searchParams: { ref_name: ref } }, schema, - errorMessages: errorMessagesFor('project not found'), + httpErrors: httpErrorsFor('project not found'), }) } diff --git a/services/gitlab/gitlab-license.service.js b/services/gitlab/gitlab-license.service.js index 254696121cc86..131173ba8aa65 100644 --- a/services/gitlab/gitlab-license.service.js +++ b/services/gitlab/gitlab-license.service.js @@ -1,7 +1,7 @@ import Joi from 'joi' import { optionalUrl } from '../validators.js' import { renderLicenseBadge } from '../licenses.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' const schema = Joi.object({ @@ -67,7 +67,7 @@ export default class GitlabLicense extends GitLabBase { schema, url: `${baseUrl}/api/v4/projects/${encodeURIComponent(project)}`, options: { searchParams: { license: '1' } }, - errorMessages: errorMessagesFor('project not found'), + httpErrors: httpErrorsFor('project not found'), }) } diff --git a/services/gitlab/gitlab-merge-requests.service.js b/services/gitlab/gitlab-merge-requests.service.js index bc7f7b88a102d..5db63bcb6e29e 100644 --- a/services/gitlab/gitlab-merge-requests.service.js +++ b/services/gitlab/gitlab-merge-requests.service.js @@ -1,7 +1,7 @@ import Joi from 'joi' import { optionalUrl, nonNegativeInteger } from '../validators.js' import { metric } from '../text-formatters.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' // The total number of MR is in the `x-total` field in the headers. @@ -314,7 +314,7 @@ export default class GitlabMergeRequests extends GitLabBase { labels, }, }, - errorMessages: errorMessagesFor('project not found'), + httpErrors: httpErrorsFor('project not found'), }) ) return this.constructor._validate(res.headers, schema) diff --git a/services/gitlab/gitlab-pipeline-coverage.service.js b/services/gitlab/gitlab-pipeline-coverage.service.js index 3267e8e4eb23b..e0a332907b34d 100644 --- a/services/gitlab/gitlab-pipeline-coverage.service.js +++ b/services/gitlab/gitlab-pipeline-coverage.service.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { coveragePercentage } from '../color-formatters.js' import { optionalUrl } from '../validators.js' import { BaseSvgScrapingService, NotFound } from '../index.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' const schema = Joi.object({ message: Joi.string() @@ -98,11 +98,11 @@ export default class GitlabPipelineCoverage extends BaseSvgScrapingService { const url = `${baseUrl}/${decodeURIComponent( project )}/badges/${branch}/coverage.svg${jobName}` - const errorMessages = errorMessagesFor('project not found') + const httpErrors = httpErrorsFor('project not found') return this._requestSvg({ schema, url, - errorMessages, + httpErrors, }) } diff --git a/services/gitlab/gitlab-pipeline-status.service.js b/services/gitlab/gitlab-pipeline-status.service.js index dbd0cdbcd1f76..49246f861d922 100644 --- a/services/gitlab/gitlab-pipeline-status.service.js +++ b/services/gitlab/gitlab-pipeline-status.service.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { isBuildStatus, renderBuildStatusBadge } from '../build-status.js' import { optionalUrl } from '../validators.js' import { BaseSvgScrapingService, NotFound, redirector } from '../index.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' const badgeSchema = Joi.object({ message: Joi.alternatives() @@ -73,7 +73,7 @@ class GitlabPipelineStatus extends BaseSvgScrapingService { url: `${baseUrl}/${decodeURIComponent( project )}/badges/${branch}/pipeline.svg`, - errorMessages: errorMessagesFor('project not found'), + httpErrors: httpErrorsFor('project not found'), }) } diff --git a/services/gitlab/gitlab-release.service.js b/services/gitlab/gitlab-release.service.js index 51f3c37291b4f..28e3872b0cfcb 100644 --- a/services/gitlab/gitlab-release.service.js +++ b/services/gitlab/gitlab-release.service.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { optionalUrl } from '../validators.js' import { latest, renderVersionBadge } from '../version.js' import { NotFound } from '../index.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' const schema = Joi.array().items( @@ -98,7 +98,7 @@ export default class GitLabRelease extends GitLabBase { return this.fetchPaginatedArrayData({ schema, url: `${baseUrl}/api/v4/projects/${encodeURIComponent(project)}/releases`, - errorMessages: errorMessagesFor('project not found'), + httpErrors: httpErrorsFor('project not found'), options: { searchParams: { order_by: orderBy }, }, diff --git a/services/gitlab/gitlab-stars.service.js b/services/gitlab/gitlab-stars.service.js index a440c814f34a1..695c0db3916fa 100644 --- a/services/gitlab/gitlab-stars.service.js +++ b/services/gitlab/gitlab-stars.service.js @@ -58,7 +58,7 @@ export default class GitlabStars extends GitLabBase { return super.fetch({ schema, url: `${baseUrl}/api/v4/projects/${encodeURIComponent(project)}`, - errorMessages: { + httpErrors: { 404: 'project not found', }, }) diff --git a/services/gitlab/gitlab-tag.service.js b/services/gitlab/gitlab-tag.service.js index 534d3719729b8..10f7bd62ed7a1 100644 --- a/services/gitlab/gitlab-tag.service.js +++ b/services/gitlab/gitlab-tag.service.js @@ -4,7 +4,7 @@ import { optionalUrl } from '../validators.js' import { latest } from '../version.js' import { addv } from '../text-formatters.js' import { NotFound } from '../index.js' -import { documentation, errorMessagesFor } from './gitlab-helper.js' +import { documentation, httpErrorsFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' const schema = Joi.array().items( @@ -92,7 +92,7 @@ export default class GitlabTag extends GitLabBase { project )}/repository/tags`, options: { searchParams: { order_by: 'updated' } }, - errorMessages: errorMessagesFor('project not found'), + httpErrors: httpErrorsFor('project not found'), }) } diff --git a/services/hackernews/hackernews-user-karma.service.js b/services/hackernews/hackernews-user-karma.service.js index 6ff5638ba7879..8d37f841f37b4 100644 --- a/services/hackernews/hackernews-user-karma.service.js +++ b/services/hackernews/hackernews-user-karma.service.js @@ -44,7 +44,7 @@ export default class HackerNewsUserKarma extends BaseJsonService { return this._requestJson({ schema, url: `https://hacker-news.firebaseio.com/v0/user/${id}.json`, - errorMessages: { + httpErrors: { 404: 'user not found', }, }) diff --git a/services/homebrew/homebrew-downloads.service.js b/services/homebrew/homebrew-downloads.service.js index 20e19b23e4763..e7989e48b362a 100644 --- a/services/homebrew/homebrew-downloads.service.js +++ b/services/homebrew/homebrew-downloads.service.js @@ -53,7 +53,7 @@ export default class HomebrewDownloads extends BaseJsonService { return this._requestJson({ schema, url: `https://formulae.brew.sh/api/formula/${formula}.json`, - errorMessages: { 404: 'formula not found' }, + httpErrors: { 404: 'formula not found' }, }) } diff --git a/services/jenkins/jenkins-base.js b/services/jenkins/jenkins-base.js index 35398c0301475..2a52b2d47640b 100644 --- a/services/jenkins/jenkins-base.js +++ b/services/jenkins/jenkins-base.js @@ -11,14 +11,14 @@ export default class JenkinsBase extends BaseJsonService { url, schema, searchParams, - errorMessages = { 404: 'instance or job not found' }, + httpErrors = { 404: 'instance or job not found' }, }) { return this._requestJson( this.authHelper.withBasicAuth({ url, options: { searchParams }, schema, - errorMessages, + httpErrors, }) ) } diff --git a/services/jenkins/jenkins-coverage.service.js b/services/jenkins/jenkins-coverage.service.js index 9727fdca4b6b2..c072abe7c2c01 100644 --- a/services/jenkins/jenkins-coverage.service.js +++ b/services/jenkins/jenkins-coverage.service.js @@ -138,7 +138,7 @@ export default class JenkinsCoverage extends JenkinsBase { url: buildUrl({ jobUrl, plugin: pluginSpecificPath }), schema, searchParams: buildTreeParamQueryString(treeQueryParam), - errorMessages: { + httpErrors: { 404: 'job or coverage not found', }, }) diff --git a/services/jenkins/jenkins-plugin-installs.service.js b/services/jenkins/jenkins-plugin-installs.service.js index 456d2071b61e2..ce51df17180dd 100644 --- a/services/jenkins/jenkins-plugin-installs.service.js +++ b/services/jenkins/jenkins-plugin-installs.service.js @@ -63,7 +63,7 @@ export default class JenkinsPluginInstalls extends BaseJsonService { return this._requestJson({ url: `https://stats.jenkins.io/plugin-installation-trend/${plugin}.stats.json`, schema: version ? schemaInstallationsPerVersion : schemaInstallations, - errorMessages: { + httpErrors: { 404: 'plugin not found', }, }) diff --git a/services/jetbrains/jetbrains-base.js b/services/jetbrains/jetbrains-base.js index ea8bc5d5c15f4..fe3c497c4797d 100644 --- a/services/jetbrains/jetbrains-base.js +++ b/services/jetbrains/jetbrains-base.js @@ -54,7 +54,7 @@ export default class JetbrainsBase extends BaseXmlService { return super._validate(data, schema) } - async _requestJson({ schema, url, options = {}, errorMessages = {} }) { + async _requestJson({ schema, url, options = {}, httpErrors = {} }) { const mergedOptions = { ...{ headers: { Accept: 'application/json' } }, ...options, @@ -62,7 +62,7 @@ export default class JetbrainsBase extends BaseXmlService { const { buffer } = await this._request({ url, options: mergedOptions, - errorMessages, + httpErrors, }) const json = this._parseJson(buffer) return this.constructor._validateJson(json, schema) diff --git a/services/jetbrains/jetbrains-downloads.service.js b/services/jetbrains/jetbrains-downloads.service.js index fc91c78ce3f76..7db2403e28ca2 100644 --- a/services/jetbrains/jetbrains-downloads.service.js +++ b/services/jetbrains/jetbrains-downloads.service.js @@ -56,7 +56,7 @@ export default class JetbrainsDownloads extends JetbrainsBase { url: `https://plugins.jetbrains.com/api/plugins/${this.constructor._cleanPluginId( pluginId )}`, - errorMessages: { 400: 'not found' }, + httpErrors: { 400: 'not found' }, }) downloads = jetbrainsPluginData.downloads } diff --git a/services/jetbrains/jetbrains-rating.service.js b/services/jetbrains/jetbrains-rating.service.js index 81fa3fb61ba26..5c3fd2d7573fa 100644 --- a/services/jetbrains/jetbrains-rating.service.js +++ b/services/jetbrains/jetbrains-rating.service.js @@ -92,7 +92,7 @@ export default class JetbrainsRating extends JetbrainsBase { url: `https://plugins.jetbrains.com/api/plugins/${this.constructor._cleanPluginId( pluginId )}/rating`, - errorMessages: { 400: 'not found' }, + httpErrors: { 400: 'not found' }, }) let voteSum = 0 diff --git a/services/jetbrains/jetbrains-version.service.js b/services/jetbrains/jetbrains-version.service.js index 2b7d8dd3b2b07..dad18b10a9b3e 100644 --- a/services/jetbrains/jetbrains-version.service.js +++ b/services/jetbrains/jetbrains-version.service.js @@ -67,7 +67,7 @@ export default class JetbrainsVersion extends JetbrainsBase { url: `https://plugins.jetbrains.com/api/plugins/${this.constructor._cleanPluginId( pluginId )}/updates`, - errorMessages: { 400: 'not found' }, + httpErrors: { 400: 'not found' }, }) version = jetbrainsPluginData[0].version } diff --git a/services/jira/jira-issue.service.js b/services/jira/jira-issue.service.js index 35fafa60a3a9b..609c81dd1df11 100644 --- a/services/jira/jira-issue.service.js +++ b/services/jira/jira-issue.service.js @@ -75,7 +75,7 @@ export default class JiraIssue extends BaseJsonService { this.authHelper.withBasicAuth({ schema, url: `${baseUrl}/rest/api/2/issue/${encodeURIComponent(issueKey)}`, - errorMessages: { 404: 'issue not found' }, + httpErrors: { 404: 'issue not found' }, }) ) diff --git a/services/jira/jira-sprint.service.js b/services/jira/jira-sprint.service.js index eaf6b0bcc31e4..2ab4d31a673ac 100644 --- a/services/jira/jira-sprint.service.js +++ b/services/jira/jira-sprint.service.js @@ -92,7 +92,7 @@ export default class JiraSprint extends BaseJsonService { maxResults: 500, }, }, - errorMessages: { + httpErrors: { 400: 'sprint not found', 404: 'sprint not found', }, diff --git a/services/jitpack/jitpack-version.service.js b/services/jitpack/jitpack-version.service.js index 8420ee58c0540..7b088dbffeea1 100644 --- a/services/jitpack/jitpack-version.service.js +++ b/services/jitpack/jitpack-version.service.js @@ -37,7 +37,7 @@ export default class JitPackVersion extends BaseJsonService { return this._requestJson({ schema, url, - errorMessages: { 401: 'project not found or private' }, + httpErrors: { 401: 'project not found or private' }, }) } diff --git a/services/librariesio/librariesio-base.js b/services/librariesio/librariesio-base.js index 26183df917a1c..850db1e63be8c 100644 --- a/services/librariesio/librariesio-base.js +++ b/services/librariesio/librariesio-base.js @@ -26,7 +26,7 @@ export default class LibrariesIoBase extends BaseJsonService { url: `/${encodeURIComponent(platform)}/${ scope ? encodeURIComponent(`${scope}/`) : '' }${encodeURIComponent(packageName)}`, - errorMessages: { 404: 'package not found' }, + httpErrors: { 404: 'package not found' }, }) } } diff --git a/services/librariesio/librariesio-dependencies.service.js b/services/librariesio/librariesio-dependencies.service.js index 6c8190534de7c..5e12a480332a5 100644 --- a/services/librariesio/librariesio-dependencies.service.js +++ b/services/librariesio/librariesio-dependencies.service.js @@ -92,7 +92,7 @@ class LibrariesIoProjectDependencies extends LibrariesIoBase { const json = await this._requestJson({ url, schema, - errorMessages: { 404: 'package or version not found' }, + httpErrors: { 404: 'package or version not found' }, }) const { deprecatedCount, outdatedCount } = transform(json) return renderDependenciesBadge({ deprecatedCount, outdatedCount }) @@ -127,7 +127,7 @@ class LibrariesIoRepoDependencies extends LibrariesIoBase { const json = await this._requestJson({ url, schema, - errorMessages: { + httpErrors: { 404: 'repo not found', }, }) diff --git a/services/localizely/localizely.service.js b/services/localizely/localizely.service.js index 47c301453be40..1dc13f9478021 100644 --- a/services/localizely/localizely.service.js +++ b/services/localizely/localizely.service.js @@ -111,7 +111,7 @@ export default class Localizely extends BaseJsonService { searchParams: { branch }, headers: { 'X-Api-Token': apiToken }, }, - errorMessages: { + httpErrors: { 403: 'not authorized for project', }, }) diff --git a/services/luarocks/luarocks.service.js b/services/luarocks/luarocks.service.js index 2ffb68616afad..49d75fbe4b6e7 100644 --- a/services/luarocks/luarocks.service.js +++ b/services/luarocks/luarocks.service.js @@ -60,7 +60,7 @@ export default class Luarocks extends BaseJsonService { user )}/manifest.json`, schema, - errorMessages: { + httpErrors: { 404: 'user not found', }, }) diff --git a/services/matrix/matrix.service.js b/services/matrix/matrix.service.js index 50c28ad84747d..8371388e02d56 100644 --- a/services/matrix/matrix.service.js +++ b/services/matrix/matrix.service.js @@ -116,7 +116,7 @@ export default class Matrix extends BaseJsonService { auth: { type: 'm.login.dummy' }, }), }, - errorMessages: { + httpErrors: { 401: 'auth failed', 403: 'guests not allowed', }, @@ -134,7 +134,7 @@ export default class Matrix extends BaseJsonService { access_token: accessToken, }, }, - errorMessages: { + httpErrors: { 401: 'bad auth token', 404: 'room not found', }, @@ -172,7 +172,7 @@ export default class Matrix extends BaseJsonService { access_token: accessToken, }, }, - errorMessages: { + httpErrors: { 400: 'unknown request', 401: 'bad auth token', 403: 'room not world readable or is invalid', diff --git a/services/nexus/nexus.service.js b/services/nexus/nexus.service.js index 8f13df2b46213..b2b166a719731 100644 --- a/services/nexus/nexus.service.js +++ b/services/nexus/nexus.service.js @@ -220,7 +220,7 @@ export default class Nexus extends BaseJsonService { schema, url, options: { searchParams }, - errorMessages: { + httpErrors: { 404: 'artifact not found', }, }) @@ -261,7 +261,7 @@ export default class Nexus extends BaseJsonService { schema: nexus3SearchApiSchema, url, options: { searchParams }, - errorMessages: { + httpErrors: { 404: 'artifact not found', }, }) diff --git a/services/npm/npm-base.js b/services/npm/npm-base.js index 7f8ed6cbc2ca3..b4dc250d620cb 100644 --- a/services/npm/npm-base.js +++ b/services/npm/npm-base.js @@ -117,7 +117,7 @@ export default class NpmBase extends BaseJsonService { // We don't validate here because we need to pluck the desired subkey first. schema: Joi.any(), url, - errorMessages: { 404: 'package not found' }, + httpErrors: { 404: 'package not found' }, }) let packageData diff --git a/services/npm/npm-downloads.service.js b/services/npm/npm-downloads.service.js index 9745b5db53053..ea6ea7eefcbbe 100644 --- a/services/npm/npm-downloads.service.js +++ b/services/npm/npm-downloads.service.js @@ -77,7 +77,7 @@ export default class NpmDownloads extends BaseJsonService { const json = await this._requestJson({ schema, url: `https://api.npmjs.org/downloads/${query}/${slug}`, - errorMessages: { 404: 'package not found or too new' }, + httpErrors: { 404: 'package not found or too new' }, }) const downloadCount = transform(json) diff --git a/services/npm/npm-version.service.js b/services/npm/npm-version.service.js index 20caf3e9984c8..80fd3c9e09bce 100644 --- a/services/npm/npm-version.service.js +++ b/services/npm/npm-version.service.js @@ -80,7 +80,7 @@ export default class NpmVersion extends NpmBase { const packageData = await this._requestJson({ schema, url: `${registryUrl}/-/package/${slug}/dist-tags`, - errorMessages: { 404: 'package not found' }, + httpErrors: { 404: 'package not found' }, }) if (tag && !(tag in packageData)) { diff --git a/services/npms-io/npms-io-score.service.js b/services/npms-io/npms-io-score.service.js index b0f48910894c6..6de07aa4dd4cb 100644 --- a/services/npms-io/npms-io-score.service.js +++ b/services/npms-io/npms-io-score.service.js @@ -77,7 +77,7 @@ export default class NpmsIOScore extends BaseJsonService { const json = await this._requestJson({ schema: responseSchema, url, - errorMessages: { 404: 'package not found or too new' }, + httpErrors: { 404: 'package not found or too new' }, }) const scoreType = type.slice(0, -6) diff --git a/services/open-vsx/open-vsx-base.js b/services/open-vsx/open-vsx-base.js index d17a1e66a8cf7..b7a79656604bb 100644 --- a/services/open-vsx/open-vsx-base.js +++ b/services/open-vsx/open-vsx-base.js @@ -34,7 +34,7 @@ export default class OpenVSXBase extends BaseJsonService { url: `https://open-vsx.org/api/${namespace}/${extension}/${ version || '' }`, - errorMessages: { + httpErrors: { 400: 'invalid extension id', 404: 'extension not found', }, diff --git a/services/opencollective/opencollective-base.js b/services/opencollective/opencollective-base.js index 9019820997d7c..203cfabf03274 100644 --- a/services/opencollective/opencollective-base.js +++ b/services/opencollective/opencollective-base.js @@ -43,7 +43,7 @@ export default class OpencollectiveBase extends BaseJsonService { schema: collectiveDetailsSchema, // https://developer.opencollective.com/#/api/collectives?id=get-info url: `https://opencollective.com/${collective}.json`, - errorMessages: { + httpErrors: { 404: 'collective not found', }, }) @@ -66,7 +66,7 @@ export default class OpencollectiveBase extends BaseJsonService { url: `https://opencollective.com/${collective}/members/${ userType || 'all' }.json${tierId ? `?TierId=${tierId}` : ''}`, - errorMessages: { + httpErrors: { 404: 'collective not found', }, }) diff --git a/services/opm/opm-version.service.js b/services/opm/opm-version.service.js index b0c8b5e7fe0f2..e05358862870b 100644 --- a/services/opm/opm-version.service.js +++ b/services/opm/opm-version.service.js @@ -34,7 +34,7 @@ export default class OpmVersion extends BaseService { name: moduleName, }, }, - errorMessages: { + httpErrors: { 404: 'module not found', }, }) diff --git a/services/ossf-scorecard/ossf-scorecard.service.js b/services/ossf-scorecard/ossf-scorecard.service.js index a7489bcd6710b..9d17322943de4 100644 --- a/services/ossf-scorecard/ossf-scorecard.service.js +++ b/services/ossf-scorecard/ossf-scorecard.service.js @@ -41,7 +41,7 @@ export default class OSSFScorecard extends BaseJsonService { return this._requestJson({ schema, url: `https://api.securityscorecards.dev/projects/${host}/${orgName}/${repoName}`, - errorMessages: { + httpErrors: { 404: 'invalid repo path', }, }) diff --git a/services/piwheels/piwheels-version.service.js b/services/piwheels/piwheels-version.service.js index 51be963d6e24d..b83e341c03a08 100644 --- a/services/piwheels/piwheels-version.service.js +++ b/services/piwheels/piwheels-version.service.js @@ -55,7 +55,7 @@ export default class PiWheelsVersion extends BaseJsonService { return this._requestJson({ schema, url: `https://www.piwheels.org/project/${wheel}/json/`, - errorMessages: { 404: 'package not found' }, + httpErrors: { 404: 'package not found' }, }) } diff --git a/services/pypi/pypi-base.js b/services/pypi/pypi-base.js index 012af06f49740..48f7e43f8394b 100644 --- a/services/pypi/pypi-base.js +++ b/services/pypi/pypi-base.js @@ -30,7 +30,7 @@ export default class PypiBase extends BaseJsonService { return this._requestJson({ schema, url: `https://pypi.org/pypi/${egg}/json`, - errorMessages: { 404: 'package or version not found' }, + httpErrors: { 404: 'package or version not found' }, }) } } diff --git a/services/pypi/pypi-downloads.service.js b/services/pypi/pypi-downloads.service.js index abc0647f30a3e..d6449bcdcdd74 100644 --- a/services/pypi/pypi-downloads.service.js +++ b/services/pypi/pypi-downloads.service.js @@ -59,7 +59,7 @@ export default class PypiDownloads extends BaseJsonService { return this._requestJson({ url: `https://pypistats.org/api/packages/${packageName.toLowerCase()}/recent`, schema, - errorMessages: { 404: 'package not found' }, + httpErrors: { 404: 'package not found' }, }) } diff --git a/services/reddit/subreddit-subscribers.service.js b/services/reddit/subreddit-subscribers.service.js index 2d0ce5c53d7d3..d162e6fd0c626 100644 --- a/services/reddit/subreddit-subscribers.service.js +++ b/services/reddit/subreddit-subscribers.service.js @@ -48,7 +48,7 @@ export default class RedditSubredditSubscribers extends BaseJsonService { return this._requestJson({ schema, url: `https://www.reddit.com/r/${subreddit}/about.json`, - errorMessages: { + httpErrors: { 404: 'subreddit not found', 403: 'subreddit is private', }, diff --git a/services/reddit/user-karma.service.js b/services/reddit/user-karma.service.js index b53edfc68a393..fe873aa046618 100644 --- a/services/reddit/user-karma.service.js +++ b/services/reddit/user-karma.service.js @@ -53,7 +53,7 @@ export default class RedditUserKarma extends BaseJsonService { return this._requestJson({ schema, url: `https://www.reddit.com/u/${user}/about.json`, - errorMessages: { + httpErrors: { 404: 'user not found', }, }) diff --git a/services/reuse/reuse-compliance.service.js b/services/reuse/reuse-compliance.service.js index 93933f5f9008d..2473572d37263 100644 --- a/services/reuse/reuse-compliance.service.js +++ b/services/reuse/reuse-compliance.service.js @@ -41,7 +41,7 @@ export default class Reuse extends BaseJsonService { return await this._requestJson({ schema: responseSchema, url: `https://api.reuse.software/status/${remote}`, - errorMessages: { + httpErrors: { 400: 'Not a Git repository', }, }) diff --git a/services/scrutinizer/scrutinizer-base.js b/services/scrutinizer/scrutinizer-base.js index 918a9b6dec49d..90f4fe9062f35 100644 --- a/services/scrutinizer/scrutinizer-base.js +++ b/services/scrutinizer/scrutinizer-base.js @@ -6,7 +6,7 @@ export default class ScrutinizerBase extends BaseJsonService { return this._requestJson({ schema, url: `https://scrutinizer-ci.com/api/repositories/${vcs}/${slug}`, - errorMessages: { + httpErrors: { 401: 'not authorized to access project', 404: 'project not found', }, diff --git a/services/snyk/snyk-vulnerability-base.js b/services/snyk/snyk-vulnerability-base.js index 39a5fd33f9e7d..ee25d1dd449c6 100644 --- a/services/snyk/snyk-vulnerability-base.js +++ b/services/snyk/snyk-vulnerability-base.js @@ -25,14 +25,14 @@ export default class SnykVulnerabilityBase extends BaseSvgScrapingService { } } - async fetch({ url, searchParams, errorMessages }) { + async fetch({ url, searchParams, httpErrors }) { const { message: vulnerabilities } = await this._requestSvg({ url, schema, options: { searchParams, }, - errorMessages, + httpErrors, }) return { vulnerabilities } diff --git a/services/snyk/snyk-vulnerability-github.service.js b/services/snyk/snyk-vulnerability-github.service.js index 535dc311143f2..7611e4ffd4e6c 100644 --- a/services/snyk/snyk-vulnerability-github.service.js +++ b/services/snyk/snyk-vulnerability-github.service.js @@ -39,7 +39,7 @@ export default class SnykVulnerabilityGitHub extends SynkVulnerabilityBase { const { vulnerabilities } = await this.fetch({ url, searchParams, - errorMessages: { + httpErrors: { 404: 'repo or manifest not found', }, }) diff --git a/services/snyk/snyk-vulnerability-npm.service.js b/services/snyk/snyk-vulnerability-npm.service.js index 4e5f99db3e18f..5043608400e5d 100644 --- a/services/snyk/snyk-vulnerability-npm.service.js +++ b/services/snyk/snyk-vulnerability-npm.service.js @@ -43,7 +43,7 @@ export default class SnykVulnerabilityNpm extends SynkVulnerabilityBase { // Snyk returns an HTTP 200 with an HTML page when the specified // npm package is not found that contains the text 404. // Including this in case Snyk starts returning a 404 response code instead. - errorMessages: { + httpErrors: { 404: 'npm package is invalid or does not exist', }, }) diff --git a/services/sonar/sonar-base.js b/services/sonar/sonar-base.js index 2e4fd807ca20f..aaa29d3346df3 100644 --- a/services/sonar/sonar-base.js +++ b/services/sonar/sonar-base.js @@ -84,7 +84,7 @@ export default class SonarBase extends BaseJsonService { schema, url, options: { searchParams }, - errorMessages: { + httpErrors: { 404: 'component or metric not found, or legacy API not supported', }, }) diff --git a/services/sourceforge/sourceforge-base.js b/services/sourceforge/sourceforge-base.js index c8e84ed0dfa1e..e1c973a8cf16e 100644 --- a/services/sourceforge/sourceforge-base.js +++ b/services/sourceforge/sourceforge-base.js @@ -5,7 +5,7 @@ export default class BaseSourceForgeService extends BaseJsonService { return this._requestJson({ url: `https://sourceforge.net/rest/p/${project}/`, schema, - errorMessages: { + httpErrors: { 404: 'project not found', }, }) diff --git a/services/sourceforge/sourceforge-commit-count.service.js b/services/sourceforge/sourceforge-commit-count.service.js index 581f4384c22cd..d7c9f8927502b 100644 --- a/services/sourceforge/sourceforge-commit-count.service.js +++ b/services/sourceforge/sourceforge-commit-count.service.js @@ -39,7 +39,7 @@ export default class SourceforgeCommitCount extends BaseJsonService { return this._requestJson({ url: `https://sourceforge.net/rest/p/${project}/git`, schema, - errorMessages: { + httpErrors: { 404: 'project not found', }, }) diff --git a/services/sourceforge/sourceforge-downloads.service.js b/services/sourceforge/sourceforge-downloads.service.js index f382b5c1e2af3..134c52f20cd82 100644 --- a/services/sourceforge/sourceforge-downloads.service.js +++ b/services/sourceforge/sourceforge-downloads.service.js @@ -91,7 +91,7 @@ export default class SourceforgeDownloads extends BaseJsonService { schema, url, options, - errorMessages: { + httpErrors: { 404: 'project not found', }, }) diff --git a/services/sourceforge/sourceforge-last-commit.service.js b/services/sourceforge/sourceforge-last-commit.service.js index 9e6acfb38f32a..5b4315af6f347 100644 --- a/services/sourceforge/sourceforge-last-commit.service.js +++ b/services/sourceforge/sourceforge-last-commit.service.js @@ -46,7 +46,7 @@ export default class SourceforgeLastCommit extends BaseJsonService { return this._requestJson({ url: `https://sourceforge.net/rest/p/${project}/git/commits`, schema, - errorMessages: { + httpErrors: { 404: 'project not found', }, }) diff --git a/services/sourceforge/sourceforge-open-tickets.service.js b/services/sourceforge/sourceforge-open-tickets.service.js index 7cf956105b830..d6fa6b2c26a2e 100644 --- a/services/sourceforge/sourceforge-open-tickets.service.js +++ b/services/sourceforge/sourceforge-open-tickets.service.js @@ -43,7 +43,7 @@ export default class SourceforgeOpenTickets extends BaseJsonService { return this._requestJson({ schema, url, - errorMessages: { + httpErrors: { 404: 'project not found', }, }) diff --git a/services/spack/spack.service.js b/services/spack/spack.service.js index c3ad8e527fb3d..a052431d74bd0 100644 --- a/services/spack/spack.service.js +++ b/services/spack/spack.service.js @@ -32,7 +32,7 @@ export default class SpackVersion extends BaseJsonService { return this._requestJson({ schema, url: `https://packages.spack.io/data/packages/${packageName}.json`, - errorMessages: { + httpErrors: { 404: 'package not found', }, }) diff --git a/services/stackexchange/stackexchange-reputation.service.js b/services/stackexchange/stackexchange-reputation.service.js index db2e3df40d6c1..b75f61e39ea23 100644 --- a/services/stackexchange/stackexchange-reputation.service.js +++ b/services/stackexchange/stackexchange-reputation.service.js @@ -49,7 +49,7 @@ export default class StackExchangeReputation extends StackExchangeBase { schema: reputationSchema, options: { decompress: true, searchParams: { site: stackexchangesite } }, url: `https://api.stackexchange.com/2.2/${path}`, - errorMessages: { + httpErrors: { 400: 'invalid parameters', }, }) diff --git a/services/steam/steam-base.js b/services/steam/steam-base.js index 9ea5cae989cdc..459c6d2a7ac0f 100644 --- a/services/steam/steam-base.js +++ b/services/steam/steam-base.js @@ -45,7 +45,7 @@ class BaseSteamAPI extends BaseJsonService { return this._requestJson({ url, schema, - errorMessages: { + httpErrors: { 400: 'bad request', }, options, diff --git a/services/symfony/symfony-insight-base.js b/services/symfony/symfony-insight-base.js index 8cace75a89741..95318439afd57 100644 --- a/services/symfony/symfony-insight-base.js +++ b/services/symfony/symfony-insight-base.js @@ -62,7 +62,7 @@ class SymfonyInsightBase extends BaseXmlService { options: { headers: { Accept: 'application/vnd.com.sensiolabs.insight+xml' }, }, - errorMessages: { + httpErrors: { 401: 'not authorized to access project', 404: 'project not found', }, diff --git a/services/tas/tas-tests.service.js b/services/tas/tas-tests.service.js index b347f8caaacd8..70836b0f7c931 100644 --- a/services/tas/tas-tests.service.js +++ b/services/tas/tas-tests.service.js @@ -80,7 +80,7 @@ export default class TasBuildStatus extends BaseJsonService { return this._requestJson({ schema, url: `https://api.tas.lambdatest.com/repo/badge?git_provider=${provider}&org=${org}&repo=${repo}`, - errorMessages: { + httpErrors: { 401: 'private project not supported', 404: 'project not found', }, diff --git a/services/teamcity/teamcity-base.js b/services/teamcity/teamcity-base.js index a3b447c72dc6b..00b60da40b1cc 100644 --- a/services/teamcity/teamcity-base.js +++ b/services/teamcity/teamcity-base.js @@ -7,7 +7,7 @@ export default class TeamCityBase extends BaseJsonService { serviceKey: 'teamcity', } - async fetch({ url, schema, searchParams = {}, errorMessages = {} }) { + async fetch({ url, schema, searchParams = {}, httpErrors = {} }) { // JetBrains API Auth Docs: https://confluence.jetbrains.com/display/TCD18/REST+API#RESTAPI-RESTAuthentication const options = { searchParams } if (!this.authHelper.isConfigured) { @@ -19,7 +19,7 @@ export default class TeamCityBase extends BaseJsonService { url, schema, options, - errorMessages: { 404: 'build not found', ...errorMessages }, + httpErrors: { 404: 'build not found', ...httpErrors }, }) ) } diff --git a/services/testspace/testspace-base.js b/services/testspace/testspace-base.js index 5f74c556a0b75..556aaf2b7f879 100644 --- a/services/testspace/testspace-base.js +++ b/services/testspace/testspace-base.js @@ -35,7 +35,7 @@ export default class TestspaceBase extends BaseJsonService { return this._requestJson({ schema, url, - errorMessages: { + httpErrors: { 403: 'org not found or not authorized', 404: 'org, project, or space not found', }, diff --git a/services/tokei/tokei.service.js b/services/tokei/tokei.service.js index dd01918b8d404..2a6baeb8c5a29 100644 --- a/services/tokei/tokei.service.js +++ b/services/tokei/tokei.service.js @@ -65,7 +65,7 @@ export default class Tokei extends BaseJsonService { return this._requestJson({ schema, url: `https://tokei.rs/b1/${provider}/${user}/${repo}`, - errorMessages: { + httpErrors: { 400: 'repo not found', }, }) diff --git a/services/twitch/twitch-base.js b/services/twitch/twitch-base.js index 844157c3f1bd7..3ca2b135a011c 100644 --- a/services/twitch/twitch-base.js +++ b/services/twitch/twitch-base.js @@ -46,7 +46,7 @@ export default class TwitchBase extends BaseJsonService { grant_type: 'client_credentials', }, }, - errorMessages: { + httpErrors: { 401: 'invalid token', 404: 'node not found', }, diff --git a/services/ubuntu/ubuntu.service.js b/services/ubuntu/ubuntu.service.js index a52d61b14b6ef..fae6f52837235 100644 --- a/services/ubuntu/ubuntu.service.js +++ b/services/ubuntu/ubuntu.service.js @@ -53,7 +53,7 @@ export default class Ubuntu extends BaseJsonService { ...seriesParam, }, }, - errorMessages: { + httpErrors: { 400: 'series not found', }, }) diff --git a/services/visual-studio-app-center/visual-studio-app-center-base.js b/services/visual-studio-app-center/visual-studio-app-center-base.js index e90a6ee2f368b..72952155d5143 100644 --- a/services/visual-studio-app-center/visual-studio-app-center-base.js +++ b/services/visual-studio-app-center/visual-studio-app-center-base.js @@ -25,7 +25,7 @@ class BaseVisualStudioAppCenterService extends BaseJsonService { 'X-API-Token': token, }, }, - errorMessages: { + httpErrors: { 401: 'invalid token', 403: 'project not found', 404: 'project not found', diff --git a/services/visual-studio-marketplace/visual-studio-marketplace-base.js b/services/visual-studio-marketplace/visual-studio-marketplace-base.js index 95acda7747889..53456a91df334 100644 --- a/services/visual-studio-marketplace/visual-studio-marketplace-base.js +++ b/services/visual-studio-marketplace/visual-studio-marketplace-base.js @@ -95,7 +95,7 @@ export default class VisualStudioMarketplaceBase extends BaseJsonService { schema: extensionQuerySchema, url, options, - errorMessages: { + httpErrors: { 400: 'invalid extension id', }, }) diff --git a/services/weblate/weblate-component-license.service.js b/services/weblate/weblate-component-license.service.js index a24f5c3ab9146..2a31fa8b5c1d3 100644 --- a/services/weblate/weblate-component-license.service.js +++ b/services/weblate/weblate-component-license.service.js @@ -37,7 +37,7 @@ export default class WeblateComponentLicense extends WeblateBase { return super.fetch({ schema, url: `${server}/api/components/${project}/${component}/`, - errorMessages: { + httpErrors: { 403: 'access denied by remote server', 404: 'component not found', }, diff --git a/services/weblate/weblate-entities.service.js b/services/weblate/weblate-entities.service.js index f8db2d25ca090..26f59b4774b26 100644 --- a/services/weblate/weblate-entities.service.js +++ b/services/weblate/weblate-entities.service.js @@ -36,7 +36,7 @@ export default class WeblateEntities extends WeblateBase { return super.fetch({ schema, url: `${server}/api/${type}/`, - errorMessages: { + httpErrors: { 403: 'access denied by remote server', }, }) diff --git a/services/weblate/weblate-project-translated-percentage.service.js b/services/weblate/weblate-project-translated-percentage.service.js index e8089f3b37418..d9743b03c34b9 100644 --- a/services/weblate/weblate-project-translated-percentage.service.js +++ b/services/weblate/weblate-project-translated-percentage.service.js @@ -49,7 +49,7 @@ export default class WeblateProjectTranslatedPercentage extends WeblateBase { return super.fetch({ schema, url: `${server}/api/projects/${project}/statistics/`, - errorMessages: { + httpErrors: { 403: 'access denied by remote server', 404: 'project not found', }, diff --git a/services/weblate/weblate-user-statistic.service.js b/services/weblate/weblate-user-statistic.service.js index 639153bc68540..6a4c3a89dcf71 100644 --- a/services/weblate/weblate-user-statistic.service.js +++ b/services/weblate/weblate-user-statistic.service.js @@ -49,7 +49,7 @@ export default class WeblateUserStatistic extends WeblateBase { return super.fetch({ schema, url: `${server}/api/users/${user}/statistics/`, - errorMessages: { + httpErrors: { 403: 'access denied by remote server', 404: 'user not found', }, diff --git a/services/wheelmap/wheelmap.service.js b/services/wheelmap/wheelmap.service.js index c6abf22d8c6cd..98a43ef1d4eef 100644 --- a/services/wheelmap/wheelmap.service.js +++ b/services/wheelmap/wheelmap.service.js @@ -50,7 +50,7 @@ export default class Wheelmap extends BaseJsonService { { schema, url: `https://wheelmap.org/api/nodes/${nodeId}`, - errorMessages: { + httpErrors: { 401: 'invalid token', 404: 'node not found', },