Files
shields/services/errors.js
Paul Melnikow 282520041d Add [GitlabPipeline] badge (#2325)
There's a lot of demand for the Gitlab badges (#541) and the PR has been lingering, so I thought I'd start off one of the simple ones as a new-style service. This one is SVG-based, so it shouldn't require the API-token logic which could use some more testing and will require us to create an app and configure it on our server.

We don't have any validation in place for `queryParams`. Probably this should be added to BaseService, though for the time being I extracted a helper function.

Thanks to @LVMBDV for getting this work started in #1838!
2018-11-18 10:06:47 -05:00

109 lines
2.2 KiB
JavaScript

'use strict'
class ShieldsRuntimeError extends Error {
get name() {
return 'ShieldsRuntimeError'
}
get defaultPrettyMessage() {
throw new Error('Must implement abstract method')
}
constructor(props = {}, message) {
super(message)
this.prettyMessage = props.prettyMessage || this.defaultPrettyMessage
if (props.underlyingError) {
this.stack = props.underlyingError.stack
}
}
}
const defaultNotFoundError = 'not found'
class NotFound extends ShieldsRuntimeError {
get name() {
return 'NotFound'
}
get defaultPrettyMessage() {
return defaultNotFoundError
}
constructor(props = {}) {
const prettyMessage = props.prettyMessage || defaultNotFoundError
const message =
prettyMessage === defaultNotFoundError
? 'Not Found'
: `Not Found: ${prettyMessage}`
super(props, message)
}
}
class InvalidResponse extends ShieldsRuntimeError {
get name() {
return 'InvalidResponse'
}
get defaultPrettyMessage() {
return 'invalid'
}
constructor(props = {}) {
const message = props.underlyingError
? `Invalid Response: ${props.underlyingError.message}`
: 'Invalid Response'
super(props, message)
}
}
class Inaccessible extends ShieldsRuntimeError {
get name() {
return 'Inaccessible'
}
get defaultPrettyMessage() {
return 'inaccessible'
}
constructor(props = {}) {
const message = props.underlyingError
? `Inaccessible: ${props.underlyingError.message}`
: 'Inaccessible'
super(props, message)
}
}
class InvalidParameter extends ShieldsRuntimeError {
get name() {
return 'InvalidParameter'
}
get defaultPrettyMessage() {
return 'invalid parameter'
}
constructor(props = {}) {
const message = props.underlyingError
? `Invalid Parameter: ${props.underlyingError.message}`
: 'Invalid Parameter'
super(props, message)
}
}
class Deprecated extends ShieldsRuntimeError {
get name() {
return 'Deprecated'
}
get defaultPrettyMessage() {
return 'no longer available'
}
constructor(props) {
const message = 'Deprecated'
super(props, message)
}
}
module.exports = {
NotFound,
InvalidResponse,
Inaccessible,
InvalidParameter,
Deprecated,
}