1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.PreconditionFailedError = exports.PayloadTooLargeError = exports.ValidationError = exports.BadPathError = exports.NotEnoughProofError = exports.ConflictError = exports.DoesNotExist = exports.GaiaHubError = exports.NoSessionDataError = exports.InvalidStateError = exports.FailedDecryptionError = exports.SignatureVerificationError = exports.LoginFailedError = exports.InvalidAmountError = exports.NotEnoughFundsError = exports.InvalidDIDError = exports.RemoteServiceError = exports.MissingParameterError = exports.InvalidParameterError = exports.BlockstackError = exports.ERROR_CODES = void 0;
|
4 | exports.ERROR_CODES = {
|
5 | MISSING_PARAMETER: 'missing_parameter',
|
6 | REMOTE_SERVICE_ERROR: 'remote_service_error',
|
7 | INVALID_STATE: 'invalid_state',
|
8 | NO_SESSION_DATA: 'no_session_data',
|
9 | DOES_NOT_EXIST: 'does_not_exist',
|
10 | FAILED_DECRYPTION_ERROR: 'failed_decryption_error',
|
11 | INVALID_DID_ERROR: 'invalid_did_error',
|
12 | NOT_ENOUGH_FUNDS_ERROR: 'not_enough_error',
|
13 | INVALID_AMOUNT_ERROR: 'invalid_amount_error',
|
14 | LOGIN_FAILED_ERROR: 'login_failed',
|
15 | SIGNATURE_VERIFICATION_ERROR: 'signature_verification_failure',
|
16 | CONFLICT_ERROR: 'conflict_error',
|
17 | NOT_ENOUGH_PROOF_ERROR: 'not_enough_proof_error',
|
18 | BAD_PATH_ERROR: 'bad_path_error',
|
19 | VALIDATION_ERROR: 'validation_error',
|
20 | PAYLOAD_TOO_LARGE_ERROR: 'payload_too_large_error',
|
21 | PRECONDITION_FAILED_ERROR: 'precondition_failed_error',
|
22 | UNKNOWN: 'unknown',
|
23 | };
|
24 | Object.freeze(exports.ERROR_CODES);
|
25 | class BlockstackError extends Error {
|
26 | constructor(error) {
|
27 | super();
|
28 | let message = error.message;
|
29 | let bugDetails = `Error Code: ${error.code}`;
|
30 | let stack = this.stack;
|
31 | if (!stack) {
|
32 | try {
|
33 | throw new Error();
|
34 | }
|
35 | catch (e) {
|
36 | stack = e.stack;
|
37 | }
|
38 | }
|
39 | else {
|
40 | bugDetails += `Stack Trace:\n${stack}`;
|
41 | }
|
42 | message += `\nIf you believe this exception is caused by a bug in stacks.js,
|
43 | please file a bug report: https://github.com/blockstack/stacks.js/issues\n\n${bugDetails}`;
|
44 | this.message = message;
|
45 | this.code = error.code;
|
46 | this.parameter = error.parameter ? error.parameter : undefined;
|
47 | }
|
48 | toString() {
|
49 | return `${super.toString()}
|
50 | code: ${this.code} param: ${this.parameter ? this.parameter : 'n/a'}`;
|
51 | }
|
52 | }
|
53 | exports.BlockstackError = BlockstackError;
|
54 | class InvalidParameterError extends BlockstackError {
|
55 | constructor(parameter, message = '') {
|
56 | super({ code: exports.ERROR_CODES.MISSING_PARAMETER, message, parameter });
|
57 | this.name = 'MissingParametersError';
|
58 | }
|
59 | }
|
60 | exports.InvalidParameterError = InvalidParameterError;
|
61 | class MissingParameterError extends BlockstackError {
|
62 | constructor(parameter, message = '') {
|
63 | super({ code: exports.ERROR_CODES.MISSING_PARAMETER, message, parameter });
|
64 | this.name = 'MissingParametersError';
|
65 | }
|
66 | }
|
67 | exports.MissingParameterError = MissingParameterError;
|
68 | class RemoteServiceError extends BlockstackError {
|
69 | constructor(response, message = '') {
|
70 | super({ code: exports.ERROR_CODES.REMOTE_SERVICE_ERROR, message });
|
71 | this.response = response;
|
72 | }
|
73 | }
|
74 | exports.RemoteServiceError = RemoteServiceError;
|
75 | class InvalidDIDError extends BlockstackError {
|
76 | constructor(message = '') {
|
77 | super({ code: exports.ERROR_CODES.INVALID_DID_ERROR, message });
|
78 | this.name = 'InvalidDIDError';
|
79 | }
|
80 | }
|
81 | exports.InvalidDIDError = InvalidDIDError;
|
82 | class NotEnoughFundsError extends BlockstackError {
|
83 | constructor(leftToFund) {
|
84 | const message = `Not enough UTXOs to fund. Left to fund: ${leftToFund}`;
|
85 | super({ code: exports.ERROR_CODES.NOT_ENOUGH_FUNDS_ERROR, message });
|
86 | this.leftToFund = leftToFund;
|
87 | this.name = 'NotEnoughFundsError';
|
88 | this.message = message;
|
89 | }
|
90 | }
|
91 | exports.NotEnoughFundsError = NotEnoughFundsError;
|
92 | class InvalidAmountError extends BlockstackError {
|
93 | constructor(fees, specifiedAmount) {
|
94 | const message = `Not enough coin to fund fees transaction fees. Fees would be ${fees},` +
|
95 | ` specified spend is ${specifiedAmount}`;
|
96 | super({ code: exports.ERROR_CODES.INVALID_AMOUNT_ERROR, message });
|
97 | this.specifiedAmount = specifiedAmount;
|
98 | this.fees = fees;
|
99 | this.name = 'InvalidAmountError';
|
100 | this.message = message;
|
101 | }
|
102 | }
|
103 | exports.InvalidAmountError = InvalidAmountError;
|
104 | class LoginFailedError extends BlockstackError {
|
105 | constructor(reason) {
|
106 | const message = `Failed to login: ${reason}`;
|
107 | super({ code: exports.ERROR_CODES.LOGIN_FAILED_ERROR, message });
|
108 | this.message = message;
|
109 | this.name = 'LoginFailedError';
|
110 | }
|
111 | }
|
112 | exports.LoginFailedError = LoginFailedError;
|
113 | class SignatureVerificationError extends BlockstackError {
|
114 | constructor(reason) {
|
115 | const message = `Failed to verify signature: ${reason}`;
|
116 | super({ code: exports.ERROR_CODES.SIGNATURE_VERIFICATION_ERROR, message });
|
117 | this.message = message;
|
118 | this.name = 'SignatureVerificationError';
|
119 | }
|
120 | }
|
121 | exports.SignatureVerificationError = SignatureVerificationError;
|
122 | class FailedDecryptionError extends BlockstackError {
|
123 | constructor(message = 'Unable to decrypt cipher object.') {
|
124 | super({ code: exports.ERROR_CODES.FAILED_DECRYPTION_ERROR, message });
|
125 | this.message = message;
|
126 | this.name = 'FailedDecryptionError';
|
127 | }
|
128 | }
|
129 | exports.FailedDecryptionError = FailedDecryptionError;
|
130 | class InvalidStateError extends BlockstackError {
|
131 | constructor(message) {
|
132 | super({ code: exports.ERROR_CODES.INVALID_STATE, message });
|
133 | this.message = message;
|
134 | this.name = 'InvalidStateError';
|
135 | }
|
136 | }
|
137 | exports.InvalidStateError = InvalidStateError;
|
138 | class NoSessionDataError extends BlockstackError {
|
139 | constructor(message) {
|
140 | super({ code: exports.ERROR_CODES.INVALID_STATE, message });
|
141 | this.message = message;
|
142 | this.name = 'NoSessionDataError';
|
143 | }
|
144 | }
|
145 | exports.NoSessionDataError = NoSessionDataError;
|
146 | class GaiaHubError extends BlockstackError {
|
147 | constructor(error, response) {
|
148 | super(error);
|
149 | if (response) {
|
150 | this.hubError = {
|
151 | statusCode: response.status,
|
152 | statusText: response.statusText,
|
153 | };
|
154 | if (typeof response.body === 'string') {
|
155 | this.hubError.message = response.body;
|
156 | }
|
157 | else if (typeof response.body === 'object') {
|
158 | Object.assign(this.hubError, response.body);
|
159 | }
|
160 | }
|
161 | }
|
162 | }
|
163 | exports.GaiaHubError = GaiaHubError;
|
164 | class DoesNotExist extends GaiaHubError {
|
165 | constructor(message, response) {
|
166 | super({ message, code: exports.ERROR_CODES.DOES_NOT_EXIST }, response);
|
167 | this.name = 'DoesNotExist';
|
168 | }
|
169 | }
|
170 | exports.DoesNotExist = DoesNotExist;
|
171 | class ConflictError extends GaiaHubError {
|
172 | constructor(message, response) {
|
173 | super({ message, code: exports.ERROR_CODES.CONFLICT_ERROR }, response);
|
174 | this.name = 'ConflictError';
|
175 | }
|
176 | }
|
177 | exports.ConflictError = ConflictError;
|
178 | class NotEnoughProofError extends GaiaHubError {
|
179 | constructor(message, response) {
|
180 | super({ message, code: exports.ERROR_CODES.NOT_ENOUGH_PROOF_ERROR }, response);
|
181 | this.name = 'NotEnoughProofError';
|
182 | }
|
183 | }
|
184 | exports.NotEnoughProofError = NotEnoughProofError;
|
185 | class BadPathError extends GaiaHubError {
|
186 | constructor(message, response) {
|
187 | super({ message, code: exports.ERROR_CODES.BAD_PATH_ERROR }, response);
|
188 | this.name = 'BadPathError';
|
189 | }
|
190 | }
|
191 | exports.BadPathError = BadPathError;
|
192 | class ValidationError extends GaiaHubError {
|
193 | constructor(message, response) {
|
194 | super({ message, code: exports.ERROR_CODES.VALIDATION_ERROR }, response);
|
195 | this.name = 'ValidationError';
|
196 | }
|
197 | }
|
198 | exports.ValidationError = ValidationError;
|
199 | class PayloadTooLargeError extends GaiaHubError {
|
200 | constructor(message, response, maxUploadByteSize) {
|
201 | super({ message, code: exports.ERROR_CODES.PAYLOAD_TOO_LARGE_ERROR }, response);
|
202 | this.name = 'PayloadTooLargeError';
|
203 | this.maxUploadByteSize = maxUploadByteSize;
|
204 | }
|
205 | }
|
206 | exports.PayloadTooLargeError = PayloadTooLargeError;
|
207 | class PreconditionFailedError extends GaiaHubError {
|
208 | constructor(message, response) {
|
209 | super({ message, code: exports.ERROR_CODES.PRECONDITION_FAILED_ERROR }, response);
|
210 | this.name = 'PreconditionFailedError';
|
211 | }
|
212 | }
|
213 | exports.PreconditionFailedError = PreconditionFailedError;
|
214 |
|
\ | No newline at end of file |