Files
shields/services/errors.js
T
Paul MelnikowandGitHub 7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00

77 lines
1.6 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)
}
}
module.exports = {
NotFound,
InvalidResponse,
Inaccessible,
}