Skip to content

Commit aa3594d

Browse files
committed
added the missing src/errors folder
1 parent b341712 commit aa3594d

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

src/errors/NetworkError.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const OAuthError = require('./OAuthError');
4+
5+
/**
6+
* Error class for network related errors
7+
* @extends OAuthError
8+
*/
9+
class NetworkError extends OAuthError {
10+
/**
11+
* Create a new NetworkError
12+
* @param {string} message - Error message
13+
* @param {string} intuitTid - Intuit transaction ID
14+
*/
15+
constructor(message, intuitTid) {
16+
super(message, 'NETWORK_ERROR', 'Network request failed', intuitTid);
17+
this.name = 'NetworkError';
18+
}
19+
}
20+
21+
module.exports = NetworkError;

src/errors/OAuthError.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use strict';
2+
3+
/**
4+
* Base error class for OAuth related errors
5+
* @extends Error
6+
*/
7+
class OAuthError extends Error {
8+
/**
9+
* Create a new OAuthError
10+
* @param {string} message - Error message
11+
* @param {string} [code] - Error code
12+
* @param {string} [description] - Error description
13+
* @param {string} [intuitTid] - Intuit transaction ID
14+
* @throws {TypeError} If message is not a string
15+
*/
16+
constructor(message, code, description, intuitTid) {
17+
if (typeof message !== 'string') {
18+
throw new TypeError('Error message must be a string');
19+
}
20+
21+
// Call parent constructor
22+
super(message);
23+
24+
// Set error name
25+
this.name = 'OAuthError';
26+
27+
// Set error properties
28+
this.code = code || 'OAUTH_ERROR';
29+
this.description = description || message;
30+
this.intuitTid = intuitTid || '';
31+
32+
// Ensure proper prototype chain for instanceof checks
33+
Object.setPrototypeOf(this, OAuthError.prototype);
34+
35+
// Capture stack trace
36+
if (Error.captureStackTrace) {
37+
Error.captureStackTrace(this, OAuthError);
38+
}
39+
}
40+
41+
/**
42+
* Convert error to string representation
43+
* @returns {string} String representation of the error
44+
*/
45+
toString() {
46+
let errorString = `${this.name}: ${this.message}`;
47+
48+
if (this.code) {
49+
errorString += ` (${this.code})`;
50+
}
51+
52+
if (this.description && this.description !== this.message) {
53+
errorString += ` - ${this.description}`;
54+
}
55+
56+
if (this.intuitTid) {
57+
errorString += ` [TID: ${this.intuitTid}]`;
58+
}
59+
60+
return errorString;
61+
}
62+
63+
/**
64+
* Convert error to JSON representation
65+
* @returns {Object} JSON representation of the error
66+
*/
67+
toJSON() {
68+
return {
69+
name: this.name,
70+
message: this.message,
71+
code: this.code,
72+
description: this.description,
73+
intuitTid: this.intuitTid,
74+
stack: this.stack,
75+
};
76+
}
77+
}
78+
79+
module.exports = OAuthError;

src/errors/TokenError.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const OAuthError = require('./OAuthError');
4+
5+
/**
6+
* Error class for token related errors
7+
* @extends OAuthError
8+
*/
9+
class TokenError extends OAuthError {
10+
/**
11+
* Create a new TokenError
12+
* @param {string} message - Error message
13+
* @param {string} [code] - Error code
14+
* @param {string} [description] - Error description
15+
* @param {string} [intuitTid] - Intuit transaction ID
16+
*/
17+
constructor(message, code, description, intuitTid) {
18+
super(message, code || 'TOKEN_ERROR', description || message, intuitTid);
19+
this.name = 'TokenError';
20+
Object.setPrototypeOf(this, TokenError.prototype);
21+
}
22+
}
23+
24+
module.exports = TokenError;

src/errors/ValidationError.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const OAuthError = require('./OAuthError');
4+
5+
/**
6+
* Error class for validation related errors
7+
* @extends OAuthError
8+
*/
9+
class ValidationError extends OAuthError {
10+
/**
11+
* Create a new ValidationError
12+
* @param {string} message - Error message
13+
* @param {string} [code] - Error code
14+
* @param {string} [description] - Error description
15+
* @param {string} [intuitTid] - Intuit transaction ID
16+
*/
17+
constructor(message, code, description, intuitTid) {
18+
super(message, code || 'VALIDATION_ERROR', description || message, intuitTid);
19+
this.name = 'ValidationError';
20+
Object.setPrototypeOf(this, ValidationError.prototype);
21+
}
22+
}
23+
24+
module.exports = ValidationError;

0 commit comments

Comments
 (0)