UNPKG

782 BJavaScriptView Raw
1
2/**
3 * fetch-error.js
4 *
5 * FetchError interface for operational errors
6 */
7
8module.exports = FetchError;
9
10/**
11 * Create FetchError instance
12 *
13 * @param String message Error message for human
14 * @param String type Error type for machine
15 * @param String systemError For Node.js system error
16 * @return FetchError
17 */
18function FetchError(message, type, systemError) {
19
20 // hide custom error implementation details from end-users
21 Error.captureStackTrace(this, this.constructor);
22
23 this.name = this.constructor.name;
24 this.message = message;
25 this.type = type;
26
27 // when err.type is `system`, err.code contains system error code
28 if (systemError) {
29 this.code = this.errno = systemError.code;
30 }
31
32}
33
34require('util').inherits(FetchError, Error);