-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathException.js
More file actions
84 lines (72 loc) · 2.09 KB
/
Exception.js
File metadata and controls
84 lines (72 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
let util = require('util');
/**
* Class Aliyun_Log_Exception description
* @param {String} code 错误码
* @param {String} message 异常描述
* @param {String} requestId 请求ID
*/
function Aliyun_Log_Exception (code, message, requestId) {
let error = Error.call(this);
error.name = this.name = code || 'Error';
if (code) this.code = error.code = code;
if (message) this.message = error.message = message;
if (requestId) this.requestId = error.requestId = requestId;
Object.defineProperty(this, 'stack', {
get: function () {
return error.stack;
}
})
return this;
}
util.inherits(Aliyun_Log_Exception, Error);
/**
* The toString() method allows a class to decide how it will react when it is treated like a string.
* @return {String} error
*/
Aliyun_Log_Exception.prototype.toString = function() {
return `Aliyun_Log_Exception: \n{\n ErrorCode: ${this.code},\n ErrorMessage: ${this.message}\n RequestId: ${this.requestId}\n}\n`;
}
/**
* Get Aliyun_Log_Exception error code.
* @return {String|Number} Error code
*/
Aliyun_Log_Exception.prototype.getErrorCode = function() {
return this.code;
}
/**
* Get Aliyun_Log_Exception error message.
* @return {String} Error message
*/
Aliyun_Log_Exception.prototype.getErrorMessage = function() {
return this.message;
}
/**
* Get log service sever requestid, '' is set if client or Http error.
* @return {String} requestId
*/
Aliyun_Log_Exception.prototype.getRequestId = function() {
return this.requestId;
}
/**
* ParameterInvalid Exception
* @param {String} Error message
*/
Aliyun_Log_Exception.ParameterInvalid = function(message) {
return new this('ParameterInvalid', message);
}
/**
* ParameterInvalid Exception
* @param {String} Error message
*/
Aliyun_Log_Exception.ParameterProjectInvalid = function() {
return new this('ParameterInvalid', '缺少参数project');
}
/**
* InvalidLogSize Exception
* @param {String} Error message
*/
Aliyun_Log_Exception.InvalidLogSize = function(message) {
return new this('InvalidLogSize', message);
}
module.exports = Aliyun_Log_Exception;