This repository was archived by the owner on Aug 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.js
More file actions
109 lines (102 loc) · 2.58 KB
/
Copy patherrors.js
File metadata and controls
109 lines (102 loc) · 2.58 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* Custom error classes for NOWPayments API
* @module errors
*/
/**
* Base error class for NOWPayments API errors
* @class NOWPaymentsError
* @extends Error
*/
class NOWPaymentsError extends Error {
/**
* Creates a base error instance
* @param {string} message - Error message
* @param {string|number} code - Error code
* @param {*} [data] - Additional error data
*/
constructor(message, code, data) {
super(message);
this.name = 'NOWPaymentsError';
this.code = code;
this.data = data;
Error.captureStackTrace(this, this.constructor);
}
/**
* Returns string representation of the error
* @returns {string} Error string representation
*/
toString() {
return `${this.name} [${this.code}]: ${this.message}`;
}
/**
* Returns JSON representation of the error
* @returns {Object} Error JSON representation
*/
toJSON() {
return {
name: this.name,
code: this.code,
message: this.message,
data: this.data
};
}
}
/**
* API error class for HTTP request failures
* @class APIError
* @extends NOWPaymentsError
*/
class APIError extends NOWPaymentsError {
/**
* Creates an API error instance
* @param {string} message - API error message
* @param {number} statusCode - HTTP status code
* @param {Object} [responseData] - API response data
*/
constructor(message, statusCode, responseData) {
super(message, statusCode, responseData);
this.name = 'APIError';
this.statusCode = statusCode;
this.responseData = responseData;
}
}
/**
* Validation error class for schema validation failures
* @class ValidationError
* @extends NOWPaymentsError
*/
class ValidationError extends NOWPaymentsError {
/**
* Creates a validation error instance
* @param {string} message - Validation error message
* @param {Object} [details] - Validation error details
*/
constructor(message, details) {
super(message, 'VALIDATION_ERROR', details);
this.name = 'ValidationError';
this.details = details;
}
}
/**
* WebSocket error class for connection failures
* @class WebSocketError
* @extends NOWPaymentsError
*/
class WebSocketError extends NOWPaymentsError {
/**
* Creates a WebSocket error instance
* @param {string} message - WebSocket error message
* @param {string} code - WebSocket error code
* @param {Object} [details] - Additional error details
*/
constructor(message, code, details) {
super(message, code, details);
this.name = 'WebSocketError';
}
}
module.exports = {
NOWPaymentsError,
APIError,
ValidationError,
WebSocketError
};