(status, message)
| 1 | import { inherits } from 'util' |
| 2 | |
| 3 | export default function HTTPError (status, message) { |
| 4 | if (!(this instanceof HTTPError)) { |
| 5 | return new HTTPError(status, message) |
| 6 | } |
| 7 | |
| 8 | // Error.captureStackTrace(this, this.constructor) |
| 9 | this.name = this.constructor.name |
| 10 | |
| 11 | // If status is an object it will be of the form: |
| 12 | // {status: , message: } |
| 13 | if (typeof status === 'number') { |
| 14 | this.message = message || 'Error occurred' |
| 15 | this.status = status |
| 16 | } else { |
| 17 | const err = status |
| 18 | let _status |
| 19 | let _code |
| 20 | let _message |
| 21 | if (err && err.status) { |
| 22 | _status = err.status |
| 23 | } |
| 24 | if (err && err.code) { |
| 25 | _code = err.code |
| 26 | } |
| 27 | if (err && err.message) { |
| 28 | _message = err.message |
| 29 | } |
| 30 | this.message = message || _message |
| 31 | this.status = _status || _code === 'ENOENT' ? 404 : 500 |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | inherits(HTTPError, Error) |
no outgoing calls
no test coverage detected