Skip to content

Commit

Permalink
customExceptions --> customExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Jun 12, 2023
1 parent e7d434a commit e78a485
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 30 deletions.
6 changes: 3 additions & 3 deletions core/base-service/base-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -68,7 +68,7 @@ class BaseGraphqlService extends BaseService {
variables = {},
options = {},
httpErrorMessages = {},
customExceptions = {},
systemErrors = {},
transformJson = data => data,
transformErrors = defaultTransformErrors,
}) {
Expand All @@ -82,7 +82,7 @@ class BaseGraphqlService extends BaseService {
url,
options: mergedOptions,
errorMessages: httpErrorMessages,
customExceptions,
systemErrors,
})
const json = transformJson(this._parseJson(buffer))
if (json.errors) {
Expand Down
6 changes: 3 additions & 3 deletions core/base-service/base-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -48,7 +48,7 @@ class BaseJsonService extends BaseService {
url,
options = {},
errorMessages = {},
customExceptions = {},
systemErrors = {},
}) {
const mergedOptions = {
...{ headers: { Accept: 'application/json' } },
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions core/base-service/base-svg-scraping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -72,7 +72,7 @@ class BaseSvgScrapingService extends BaseService {
url,
options = {},
errorMessages = {},
customExceptions = {},
systemErrors = {},
}) {
const logTrace = (...args) => trace.logTrace('fetch', ...args)
const mergedOptions = {
Expand All @@ -83,7 +83,7 @@ class BaseSvgScrapingService extends BaseService {
url,
options: mergedOptions,
errorMessages,
customExceptions,
systemErrors,
})
logTrace(emojic.dart, 'Response SVG', buffer)
const data = {
Expand Down
6 changes: 3 additions & 3 deletions core/base-service/base-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -45,7 +45,7 @@ class BaseXmlService extends BaseService {
url,
options = {},
errorMessages = {},
customExceptions = {},
systemErrors = {},
parserOptions = {},
}) {
const logTrace = (...args) => trace.logTrace('fetch', ...args)
Expand All @@ -57,7 +57,7 @@ class BaseXmlService extends BaseService {
url,
options: mergedOptions,
errorMessages,
customExceptions,
systemErrors,
})
const validateResult = XMLValidator.validate(buffer)
if (validateResult !== true) {
Expand Down
6 changes: 3 additions & 3 deletions core/base-service/base-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -42,7 +42,7 @@ class BaseYamlService extends BaseService {
url,
options = {},
errorMessages = {},
customExceptions = {},
systemErrors = {},
encoding = 'utf8',
}) {
const logTrace = (...args) => trace.logTrace('fetch', ...args)
Expand All @@ -59,7 +59,7 @@ class BaseYamlService extends BaseService {
url,
options: mergedOptions,
errorMessages,
customExceptions,
systemErrors,
})
let parsed
try {
Expand Down
9 changes: 2 additions & 7 deletions core/base-service/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions core/base-service/got.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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,
})
}
Expand Down

0 comments on commit e78a485

Please sign in to comment.