* allow serviceData to override cacheSeconds with a longer value * prevent [endpoint] json cacheSeconds property exceeding service default * 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. * 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 * customExceptions --> systemErrors * errorMessages --> httpErrors
41 lines
1015 B
JavaScript
41 lines
1015 B
JavaScript
import { colorScale } from '../color-formatters.js'
|
|
import { InvalidResponse, NotFound } from '../index.js'
|
|
|
|
const documentation = `
|
|
<p>
|
|
If your GitHub badge errors, it might be because you hit GitHub's rate limits.
|
|
You can increase Shields.io's rate limit by
|
|
<a href="https://img.shields.io/github-auth">adding the Shields GitHub
|
|
application</a> using your GitHub account.
|
|
</p>
|
|
`
|
|
|
|
function issueStateColor(s) {
|
|
return { open: '2cbe4e', closed: '6f42c1' }[s]
|
|
}
|
|
|
|
function httpErrorsFor(notFoundMessage = 'repo not found') {
|
|
return {
|
|
404: notFoundMessage,
|
|
422: notFoundMessage,
|
|
}
|
|
}
|
|
|
|
function transformErrors(errors, entity = 'repo') {
|
|
if (errors[0].type === 'NOT_FOUND') {
|
|
return new NotFound({ prettyMessage: `${entity} not found` })
|
|
} else {
|
|
return new InvalidResponse({ prettyMessage: errors[0].message })
|
|
}
|
|
}
|
|
|
|
const commentsColor = colorScale([1, 3, 10, 25], undefined, true)
|
|
|
|
export {
|
|
documentation,
|
|
issueStateColor,
|
|
commentsColor,
|
|
httpErrorsFor,
|
|
transformErrors,
|
|
}
|