-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
59 lines (51 loc) · 1.77 KB
/
index.js
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
const inherits = require("util").inherits;
const VError = require("verror").VError;
module.exports.OkError = constructError("OkError", 0);
module.exports.CancelledError = constructError("CancelledError", 1);
module.exports.UnknownError = constructError("UnknownError", 2);
module.exports.InvalidArgumentError = constructError("InvalidArgumentError", 3);
module.exports.DeadlineExceededError = constructError(
"DeadlineExceededError",
4
);
module.exports.NotFoundError = constructError("NotFoundError", 5);
module.exports.AlreadyExistsError = constructError("AlreadyExistsError", 6);
module.exports.PermissionDeniedError = constructError(
"PermissionDeniedError",
7
);
module.exports.ResourceExhaustedError = constructError(
"ResourceExhaustedError",
8
);
module.exports.FailedPreconditionError = constructError(
"FailedPreconditionError",
9
);
module.exports.AbortedError = constructError("AbortedError", 10);
module.exports.OutOfRangeError = constructError("OutOfRangeError", 11);
module.exports.UnimplementedError = constructError("UnimplementedError", 12);
module.exports.InternalError = constructError("InternalError", 13);
module.exports.UnavailableError = constructError("UnavailableError", 14);
module.exports.DataLossError = constructError("DataLossError", 15);
module.exports.UnauthenticatedError = constructError(
"UnauthenticatedError",
16
);
function constructError(className, code) {
function GRPCError(...args) {
VError.apply(this, args);
// create the error object
this.code = code;
// redefine the error name
Object.defineProperty(this, "name", {
enumerable: false,
configurable: true,
value: className,
writable: true,
});
}
inherits(GRPCError, VError);
GRPCError.prototype.code = code;
return GRPCError;
}