diff options
Diffstat (limited to 'src/Exception/Http/HttpError.js')
-rw-r--r-- | src/Exception/Http/HttpError.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Exception/Http/HttpError.js b/src/Exception/Http/HttpError.js new file mode 100644 index 0000000..e86dfed --- /dev/null +++ b/src/Exception/Http/HttpError.js @@ -0,0 +1,42 @@ +export default class HttpError extends Error { + + /** + * @returns {String} + */ + get name() { + return 'HttpError'; + } + + /** + * @returns {Response} + */ + get response() { + return this._response; + } + + /** + * @returns {Number} + */ + get status() { + return this._status; + } + + /** + * + * @param {Response} response + * @param {String} statusText + */ + constructor(response, statusText = '') { + let message = `HTTP ${response.status}`; + + if(statusText.length !== 0) { + message += ` - ${statusText}`; + } else if(response.statusText.length !== 0) { + message += ` - ${response.statusText}`; + } + + super(message); + this._response = response; + this._status = response.status; + } +}
\ No newline at end of file |