Files
shields/services/dynamic/dynamic-json.service.js
chris48s 45bb786147 log 429s to sentry (attempt 2); affects [dynamic endpoint uptimerobot weblate opencollective discord github] (#9546)
* log to sentry if upstream service responds with 429

* allow services to decide which error(s) to log, default to 429

* don't log 429s from endpoint or dynamic badges

* supress 429s from uptime robot badges

* supress 429s from weblate if not calling default server

* cache opencollective badges for longer

* cache discord badges for longer

* cache github workflow badges for longer
2023-12-04 13:37:58 +00:00

56 lines
1.6 KiB
JavaScript

import { MetricNames } from '../../core/base-service/metric-helper.js'
import { BaseJsonService, queryParams } from '../index.js'
import { createRoute } from './dynamic-helpers.js'
import jsonPath from './json-path.js'
export default class DynamicJson extends jsonPath(BaseJsonService) {
static enabledMetrics = [MetricNames.SERVICE_RESPONSE_SIZE]
static route = createRoute('json')
static openApi = {
'/badge/dynamic/json': {
get: {
summary: 'Dynamic JSON Badge',
description: `<p>
The Dynamic JSON Badge allows you to extract an arbitrary value from any
JSON Document using a JSONPath selector and show it on a badge.
</p>`,
parameters: queryParams(
{
name: 'url',
description: 'The URL to a JSON document',
required: true,
example:
'https://github.com/badges/shields/raw/master/package.json',
},
{
name: 'query',
description:
'A <a href="https://jsonpath.com/">JSONPath</a> expression that will be used to query the document',
required: true,
example: '$.name',
},
{
name: 'prefix',
description: 'Optional prefix to append to the value',
example: '[',
},
{
name: 'suffix',
description: 'Optional suffix to append to the value',
example: ']',
},
),
},
},
}
async fetch({ schema, url, httpErrors }) {
return this._requestJson({
schema,
url,
httpErrors,
logErrors: [],
})
}
}