-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: Add proper error handling (#283)
Feature: Please see `doc/usage.md` for more information on error-handling.
- Loading branch information
1 parent
4572b5d
commit 5f1a177
Showing
8 changed files
with
272 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
exports.BaseError = class BaseError extends Error { | ||
/** | ||
* @class BaseError | ||
* @constructor | ||
* @private | ||
* @param {String} code Error code | ||
* @param {String} message Error message | ||
*/ | ||
constructor(code, message) { | ||
super(`${code}: ${message}`); | ||
this.code = code; | ||
} | ||
}; | ||
|
||
|
||
exports.FatalError = class FatalError extends exports.BaseError { | ||
/** | ||
* Fatal Error. Error code is `"EFATAL"`. | ||
* @class FatalError | ||
* @constructor | ||
* @param {String|Error} data Error object or message | ||
*/ | ||
constructor(data) { | ||
const error = (typeof data === 'string') ? null : data; | ||
const message = error ? error.message : data; | ||
super('EFATAL', message); | ||
if (error) this.stack = error.stack; | ||
} | ||
}; | ||
|
||
|
||
exports.ParseError = class ParseError extends exports.BaseError { | ||
/** | ||
* Error during parsing. Error code is `"EPARSE"`. | ||
* @class ParseError | ||
* @constructor | ||
* @param {String} message Error message | ||
* @param {http.IncomingMessage} response Server response | ||
*/ | ||
constructor(message, response) { | ||
super('EPARSE', message); | ||
this.response = response; | ||
} | ||
}; | ||
|
||
|
||
exports.TelegramError = class TelegramError extends exports.BaseError { | ||
/** | ||
* Error returned from Telegram. Error code is `"ETELEGRAM"`. | ||
* @class TelegramError | ||
* @constructor | ||
* @param {String} message Error message | ||
* @param {http.IncomingMessage} response Server response | ||
*/ | ||
constructor(message, response) { | ||
super('ETELEGRAM', message); | ||
this.response = response; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.