Repository: intuit/oauth-jsclient

Issue:
Error Handling
In 4.0.0 when the QuickBooks API call had an error the error result used to contain an authResponse with a json property containing the error detail like this.

```
 "json": {
      "Fault": {
        "Error": [{ "Message": "Result Set Big Error", "Detail": "Result Set Big Error : Report too large, please customize", "code": "10100", "element": "ReportName" }],
        "type": "ValidationFault"
      },
      "time": "2024-06-24T10:19:14.384-07:00"
    },
```

On 4.2.0 the json is empty.

`"json": null,`

Is there a different way to get the QuickBooks error detail? This is critical for me to correctly handle the failure in my application. Thanks

Hints from issue comments:
@rajeshgupta723: Hi @shaun-pendrigh 

QBO API error codes ref: 
https://developer.intuit.com/app/developer/qbo/docs/develop/troubleshooting/error-codes 

Error code=10100 indicates Result Set Big | The result for the query is too large.

You may want to either use pagination, or request for a smaller payload response e.g. by specifying smaller date range in the API request. 
I'll check why the response is returning json as null in this case. 

Thanks
Rajesh





https://developer.intuit.com/app/developer/qbo/docs/learn/explore-the-quickbooks-online-api/data-queries#server-response @rajeshgupta723: Hi @shaun-pendrigh 

I've created a new candidate branch release-4.2.1 and raised this PR: https://github.com/intuit/oauth-jsclient/pull/189 

Could you please review if this fixes your issues, are you able to get json response when API returns fault?
If yes, please approve my PR. 

Thanks,
Rajesh
@shaun-pendrigh: Thanks @rajeshgupta723 I will test as soon as possible.@shaun-pendrigh: @rajeshgupta723  When trying to launch the sample I get:

```
> intuit-nodejsclient@1.0.0 start
> node app

node:internal/modules/cjs/loader:1404
  throw err;
  ^

Error: Cannot find module './errors/OAuthError'
```

Looking in the code I see these lines in 4.2.1 but there is no errors folder.

```
// Move error classes to a separate file
const OAuthError = require('./errors/OAuthError');
const ValidationError = require('./errors/ValidationError');
const TokenError = require('./errors/TokenError');
```@rajeshgupta723: Hi @shaun-pendrigh Please get latest from the release-4.2.1 branch and try again. Thanks
@shaun-pendrigh: @rajeshgupta723 Thanks the example runs now. But can you please confirm where I would see the additional API error detail? I tried logging the full error object but it does not contain the "Fault" information that I rely on to interpret the error.@rajeshgupta723: Hi @shaun-pendrigh 
Thank you for your patience. Please get latest from the release-4.2.1 branch and try again. 

Here is the info on the error handling, particularly for the Fault authresponse json. Please let me know. Thanks

FYI - 

Error handling
 here's how errors from /src/errors are handled and displayed:
1. Error Classes Structure:
* OAuthError: Base error class that all other errors extend from
* ValidationError: For validation-related errors
* TokenError: For token-related errors
* NetworkError: For network-related errors

2. Error Display Methods:

a) Console Logging:
The OAuthClient class has a built-in logging system that logs errors using the log() method
Errors are logged with the format: 'error', 'Get makeAPICall () threw an exception : ', safeStringify(e)
The safeStringify() function is used to safely convert error objects to JSON strings

b) Error String Representation:
All errors have a toString() method that formats errors as:  ErrorName: message (code) - description [TID: intuitTid]  Example: OAuthError: Rate limit exceeded (RATE_LIMIT_EXCEEDED) - Too many requests, please try again later [TID: 1234-5678]  c) JSON Representation: All errors have a toJSON() method that returns
  {
    name: string,
    message: string,
    code: string,
    description: string,
    intuitTid: string,
    stack: string
  }
 3. Error Handling Locations:
a) API Calls (makeApiCall method):
Network errors (ECONNRESET, ETIMEDOUT, etc.)
Timeout errors
Rate limit errors (429)
API errors (400-500 range)
Validation errors (missing required parameters)
b) Token Operations:
Token validation errors
Token refresh errors
Token revocation errors
c) Response Validation:
Empty response errors
Missing status code errors
Rate limit errors (429)
Unauthorized errors (401)
Forbidden errors (403)

4. Error Logging Configuration:
Logging can be enabled by setting logging: true in the OAuthClient configuration
Log entries include:
* Timestamp
* Log level
* Message
* Request context
* Error details
* Environment information
* Client ID

5. Error Handling Best Practices (from README):
 try {
  await oauthClient.makeApiCall({ url: 'https://api.example.com' });
} catch (error) {
  if (error instanceof TokenError) {
    // Handle token errors
    console.error('Token error:', error.code, error.description);
  } else if (error instanceof NetworkError) {
    // Handle network errors
    console.error('Network error:', error.message);
  } else if (error instanceof ValidationError) {
    // Handle validation errors
    console.error('Validation error:', error.message);
  } else {
    // Handle other errors
    console.error('Unexpected error:', error);
  }
}

 The errors are primarily shown to users through:
1. Console logs (when logging is enabled)
2. Error objects thrown that can be caught and handled by the application
3. String representations when errors are converted to strings
4. JSON representations when errors are serialized

The error handling system provides detailed information about what went wrong, including error codes, descriptions, and transaction IDs for debugging purposes.@shaun-pendrigh: Hi @rajeshgupta723. Not sure what I am missing. This is what I have done.

- Downloaded branch 4.2.1 and unzipped
- Opened the main project and ran npm install and then npm link
- Opened the sample project and ran npm install and then npm link intuit-oauth --save
- Modified app.js changed getCompanyInfo to generate invalid call as below which is an invalid enumeration.
- Logged the error which still had no detail about the enumeration error

`.makeApiCall({ url: "https://sandbox-quickbooks.api.intuit.com/v3/company/<realmid>/reports/BalanceSheet?accounting_method=Accrual&date_macro=thisyeartolastmonth1&minorversion=75" })`

It just has this:

```
{
    "error": "Request failed with status code 400",
    "authResponse": {
        "token": { ... },
        "response": "",
        "body": "",
        "json": null,
        "intuit_tid": ""
    },
    "intuit_tid": "",
    "originalMessage": "Request failed with status code 400",
    "error_description": "",
    "message": "Request failed with status code 400"
}
```

Would appreciate if you can let me know why I don't see the detail of the error, thanks@shaun-pendrigh: Hi @rajeshgupta723 just checking if you saw my last post? Despite your explanation I am still unable to get the API call error detail in the output.@rajeshgupta723: Hi @shaun-pendrigh 
I see your point. When 400 BAD Request error (or fault) happens in the API response, we should see something details in the response Fault object json. I have added Exception analysis in the console log that will help you see the Fault error details (a snapshot is attached here). Let me know if helps. Please get latest from the release-4.2.1 branch. Thanks!

@rajeshgupta723: e.g. sample error exception analysis console logs
<img width="375" alt="Image" src="https://github.com/user-attachments/assets/862ea4d7-8b90-4698-ad72-c5a681e445d8" />@shaun-pendrigh: Thanks @rajeshgupta723, I will review these updates and test the error process again as soon as I have a gap.@rajeshgupta723: Thanks @shaun-pendrigh Assuming you had a chance to verify the updated fix. Closing the issue now. @shaun-pendrigh: Sorry @rajeshgupta723 I have not had a chance yet. I will log a new issue if required once I do get time to test.

Solution patch:
diff --git a/.eslintrc.json b/.eslintrc.json
index 43ecf7b..909f82e 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -7,16 +7,7 @@
     "strict": ["error", "safe"],
     "prefer-object-spread": "off",
     "no-param-reassign": "off",
-    "comma-dangle": [
-      "error",
-      {
-        "arrays": "always-multiline",
-        "objects": "always-multiline",
-        "imports": "always-multiline",
-        "exports": "always-multiline",
-        "functions": "never"
-      }
-    ],
+    "comma-dangle": ["error", "always-multiline"],
     "no-underscore-dangle": "off",
     "no-unused-expressions": "off"
   },
diff --git a/.gitignore b/.gitignore
index 56fbfa8..74eb5ac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,19 +1,37 @@
 # gitignore
 
+# OS generated files
 .DS_Store
 .idea
 .idea/
-.nyc_output
 .vscode/
+
+# Build and test outputs
+.nyc_output
 coverage
 bower_components
-npm-debug.*
 node_modules
-index.js
-src/index.js
 sample/node_modules
+
+# Debug logs
+npm-debug.*
+*.log
+logs/
+src/logs/
+sample/logs/
+**/logs/
+
+# Environment and config files
 sample/.env
 oauth-jsclient.iml
+
+# Package files
 package-lock.json
 yarn.lock
-src/logs/*
+
+# Source files
+index.js
+src/index.js
+
+# Other
+.qodo
diff --git a/README.md b/README.md
index b2e1419..f0ffeee 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,197 @@
 [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=shield)](https://github.com/prettier/prettier)
 [![Known Vulnerabilities](https://snyk.io/test/github/intuit/oauth-jsclient/badge.svg)](https://snyk.io/test/github/intuit/oauth-jsclient)
 
+# OAuth Client for Intuit
+
+A Node.js client for Intuit's OAuth 2.0 implementation.
+
+## Features
+
+- OAuth 2.0 authentication flow
+- Token management and refresh
+- API request handling
+- Error handling with custom error types
+- Automatic retry for transient errors
+- Structured logging
+- Response validation
+
+## Installation
+
+```bash
+npm install oauth-jsclient
+```
+
+## Usage
+
+```javascript
+const OAuthClient = require('oauth-jsclient');
+
+const oauthClient = new OAuthClient({
+  clientId: 'your_client_id',
+  clientSecret: 'your_client_secret',
+  environment: 'sandbox', // or 'production'
+  redirectUri: 'http://localhost:8000/callback',
+  logging: true // Enable logging
+});
+```
+
+## Error Handling
+
+The client provides several custom error types for better error handling:
+
+- `OAuthError`: Base error class for all OAuth related errors
+- `NetworkError`: For network related errors
+- `ValidationError`: For validation related errors
+- `TokenError`: For token related errors
+
+Example error handling:
+
+```javascript
+try {
+  await oauthClient.makeApiCall({ url: 'https://api.example.com' });
+} catch (error) {
+  if (error instanceof TokenError) {
+    // Handle token errors
+    console.error('Token error:', error.code, error.description);
+  } else if (error instanceof NetworkError) {
+    // Handle network errors
+    console.error('Network error:', error.message);
+  } else if (error instanceof ValidationError) {
+    // Handle validation errors
+    console.error('Validation error:', error.message);
+  } else {
+    // Handle other errors
+    console.error('Unexpected error:', error);
+  }
+}
+```
+
+## Retry Logic
+
+The client includes automatic retry logic for transient errors:
+
+- Maximum 3 retries
+- Exponential backoff (1s, 2s, 4s)
+- Retries on specific status codes (408, 429, 500, 502, 503, 504)
+- Retries on network errors (ECONNRESET, ETIMEDOUT, ECONNREFUSED)
+
+You can configure retry behavior:
+
+```javascript
+OAuthClient.retryConfig = {
+  maxRetries: 3,
+  retryDelay: 1000,
+  retryableStatusCodes: [408, 429, 500, 502, 503, 504],
+  retryableErrors: ['ECONNRESET', 'ETIMEDOUT', 'ECONNREFUSED']
+};
+```
+
+## Logging
+
+The client provides structured logging when enabled:
+
+```javascript
+const oauthClient = new OAuthClient({
+  // ... other config
+  logging: true
+});
+```
+
+Log entries include:
+- Timestamp
+- Log level
+- Message
+- Request context (URL, method, headers)
+- Error details (for error logs)
+- Environment information
+- Client ID
+
+Example log entry:
+```json
+{
+  "timestamp": "2024-03-14T12:00:00.000Z",
+  "level": "error",
+  "message": "API call failed",
+  "data": {
+    "error": {
+      "name": "TokenError",
+      "code": "UNAUTHORIZED",
+      "message": "Invalid or expired access token",
+      "stack": "...",
+      "intuit_tid": "1234-1234-1234-123"
+    }
+  },
+  "environment": "sandbox",
+  "clientId": "your_client_id",
+  "request": {
+    "url": "https://api.example.com",
+    "method": "GET",
+    "headers": {
+      "Authorization": "Bearer ...",
+      "Accept": "application/json"
+    }
+  }
+}
+```
+
+## Response Validation
+
+The client validates responses and throws appropriate errors for common scenarios:
+
+- 401 Unauthorized: Invalid or expired access token
+- 403 Forbidden: Insufficient permissions
+- 429 Too Many Requests: Rate limit exceeded
+- Missing or invalid response data
+- Invalid content types
+
+## API Reference
+
+### OAuthClient
+
+#### constructor(config)
+Creates a new OAuthClient instance.
+
+```javascript
+const oauthClient = new OAuthClient({
+  clientId: 'your_client_id',
+  clientSecret: 'your_client_secret',
+  environment: 'sandbox',
+  redirectUri: 'http://localhost:8000/callback',
+  logging: true
+});
+```
+
+#### makeApiCall(params)
+Makes an API call with automatic retry and error handling.
+
+```javascript
+const response = await oauthClient.makeApiCall({
+  url: 'https://api.example.com',
+  method: 'GET',
+  headers: {
+    'Custom-Header': 'value'
+  },
+  body: {
+    key: 'value'
+  }
+});
+```
+
+#### validateResponse(response)
+Validates an API response and throws appropriate errors.
+
+```javascript
+try {
+  oauthClient.validateResponse(response);
+} catch (error) {
+  // Handle validation errors
+}
+```
+
+## License
+
+Apache License 2.0
+
 # Intuit OAuth2.0 NodeJS Library
 
 The OAuth2 Nodejs Client library is meant to work with Intuit's
@@ -437,6 +628,50 @@ oauthClient
   });
 ```
 
+
+You can also make the calling using the endpoint path:
+
+```javascript
+// Body sample from API explorer examples
+const body = {
+  TrackQtyOnHand: true,
+  Name: 'Garden Supplies',
+  QtyOnHand: 10,
+  InvStartDate: '2015-01-01',
+  Type: 'Inventory',
+  IncomeAccountRef: {
+    name: 'Sales of Product Income',
+    value: '79',
+  },
+  AssetAccountRef: {
+    name: 'Inventory Asset',
+    value: '81',
+  },
+  ExpenseAccountRef: {
+    name: 'Cost of Goods Sold',
+    value: '80',
+  },
+};
+
+oauthClient
+  .makeApiCall({
+    url: '/v3/company/1234/item',
+    method: 'POST',
+    headers: {
+      'Content-Type': 'application/json',
+    },
+    body: JSON.stringify(body),
+  })
+  .then(function (response) {
+    console.log('The API response is  : ' + response);
+  })
+  .catch(function (e) {
+    console.log('The error is ' + JSON.stringify(e));
+  });
+```
+
+
+
 The client validates the ID Token and returns boolean `true` if validates successfully else it would
 throw an exception.
 
diff --git a/package.json b/package.json
index 46a02d6..e237b9c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "intuit-oauth",
-  "version": "4.2.0",
+  "version": "4.2.1",
   "description": "Intuit Node.js client for OAuth2.0 and OpenIDConnect",
   "main": "./src/OAuthClient.js",
   "scripts": {
@@ -68,7 +68,7 @@
   "homepage": "https://github.com/intuit/oauth-jsclient",
   "dependencies": {
     "atob": "2.1.2",
-    "axios": "^1.5.1",
+    "axios": "^1.9.0",
     "csrf": "^3.0.4",
     "jsonwebtoken": "^9.0.2",
     "query-string": "^6.12.1",
@@ -76,10 +76,11 @@
     "winston": "^3.1.0"
   },
   "devDependencies": {
+    "@snyk/protect": "^1.657.0",
     "btoa": "^1.2.1",
     "chai": "^4.1.2",
     "chai-as-promised": "^7.1.1",
-    "eslint": "^6.8.0",
+    "eslint": "^9.37.0",
     "eslint-config-airbnb-base": "^14.1.0",
     "eslint-config-prettier": "^6.11.0",
     "eslint-plugin-import": "^2.20.2",
@@ -87,8 +88,7 @@
     "nock": "^9.2.3",
     "nyc": "^15.0.1",
     "prettier": "^2.0.5",
-    "sinon": "^9.0.2",
-    "@snyk/protect": "^1.657.0"
+    "sinon": "^9.0.2"
   },
   "snyk": true
 }
diff --git a/sample/.gitignore b/sample/.gitignore
new file mode 100644
index 0000000..bf84c40
--- /dev/null
+++ b/sample/.gitignore
@@ -0,0 +1 @@
+ *.log
\ No newline at end of file
diff --git a/sample/app.js b/sample/app.js
index d9b659c..656fb41 100644
--- a/sample/app.js
+++ b/sample/app.js
@@ -119,11 +119,70 @@ app.get('/getCompanyInfo', function (req, res) {
   oauthClient
     .makeApiCall({ url: `${url}v3/company/${companyID}/companyinfo/${companyID}` })
     .then(function (authResponse) {
-      console.log(`\n The response for API call is :${JSON.stringify(authResponse.json)}`);
-      res.send(authResponse.json);
+      const resp = authResponse.json ? authResponse.json : authResponse.data;
+      console.log(`\n The response for API call is :${JSON.stringify(resp)}`);
+      res.send(resp);
     })
     .catch(function (e) {
-      console.error(e);
+      // Detailed error analysis
+      const errorAnalysis = {
+        // Basic error properties
+        basic: {
+          name: e.name,
+          message: e.message,
+          stack: e.stack,
+          code: e.code
+        },
+        // Response analysis
+        response: e.response ? {
+          status: e.response.status,
+          statusText: e.response.statusText,
+          headers: JSON.stringify(e.response.headers),
+          // Deep analysis of response data
+          data: JSON.stringify(e.response.data),
+          // Specific Fault object analysis
+          fault: JSON.stringify(e.response.data && e.response.data.Fault ? {
+            type: e.response.data.Fault.type,
+            error: e.response.data.Fault.Error ? e.response.data.Fault.Error.map(err => ({
+              message: err.Message,
+              detail: err.Detail,
+              code: err.code,
+              element: err.element,
+              additionalInfo: err.additionalInfo
+            })) : null,
+            timestamp: e.response.data.time
+          } : null),
+          // OAuth error fields
+          oauth: {
+            error:e.response.data && e.response.data.error,
+            error_description: e.response.data && e.response.data.error_description
+          }
+        } : null,
+        // Request analysis
+        request: e.request ? {
+          method: e.request.method,
+          path: e.request.path,
+          headers: e.request.headers
+        } : null
+      };
+
+      // Log the detailed error analysis
+      console.error('Exception Analysis:', {
+        hasFaultObject: !!(e.response && e.response.data && e.response.data.Fault),
+        faultType: e.response && e.response.data && e.response.data.Fault && e.response.data.Fault.type,
+        faultErrors: e.response && e.response.data && e.response.data.Fault && e.response.data.Fault.Error,
+        fullAnalysis: errorAnalysis
+      });
+
+      // Send error response to client
+      res.status(e.response ? e.response.status : 500).json({
+        error: true,
+        message: e.message,
+        fault: e.response && e.response.data && e.response.data.Fault ? {
+          type: e.response.data.Fault.type,
+          errors: e.response.data.Fault.Error
+        } : null
+      });
     });
 });
 
diff --git a/src/OAuthClient.js b/src/OAuthClient.js
index b40345b..833d6e0 100644
--- a/src/OAuthClient.js
+++ b/src/OAuthClient.js
@@ -37,6 +37,11 @@ const AuthResponse = require('./response/AuthResponse');
 const version = require('../package.json');
 const Token = require('./access-token/Token');
 
+// Move error classes to a separate file
+const OAuthError = require('./errors/OAuthError');
+const ValidationError = require('./errors/ValidationError');
+const TokenError = require('./errors/TokenError');
+
 /**
  * @constructor
  * @param {string} config.environment
@@ -56,6 +61,13 @@ function OAuthClient(config) {
   this.logger = null;
   this.state = new Csrf();
 
+  // Configure Axios instance
+  this.axiosInstance = axios.create({
+    validateStatus(status) {
+      return status >= 200 && status < 500;
+    },
+  });
+
   if (this.logging) {
     const dir = './logs';
     if (!fs.existsSync(dir)) {
@@ -64,7 +76,9 @@ function OAuthClient(config) {
     this.logger = winston.createLogger({
       level: 'info',
       format: winston.format.combine(
-        winston.format.timestamp(),
+        winston.format.timestamp({
+          format: 'YYYY-MM-DD HH:mm:ss.SSS Z',  // This will include local timezone offset
+        }),
         winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`),
       ),
       transports: [
@@ -90,6 +104,10 @@ OAuthClient.environment = {
   sandbox: 'https://sandbox-quickbooks.api.intuit.com/',
   production: 'https://quickbooks.api.intuit.com/',
 };
+OAuthClient.qbo_environment = {
+  sandbox: 'https://sandbox.qbo.intuit.com/app/',
+  production: 'https://qbo.intuit.com/app/',
+};
 OAuthClient.jwks_uri = 'https://oauth.platform.intuit.com/op/v1/jwks';
 OAuthClient.scopes = {
   Accounting: 'com.intuit.quickbooks.accounting',
@@ -123,6 +141,16 @@ OAuthClient.prototype.setAuthorizeURLs = function setAuthorizeURLs(params) {
   return this;
 };
 
+OAuthClient.prototype.getEnvironmentURI = function getEnvironmentURI() { 
+  return (this.environment && this.environment === 'production') ? OAuthClient.environment.production : OAuthClient.environment.sandbox;
+}
+
+
+OAuthClient.prototype.getQBOEnvironmentURI = function getQBOEnvironmentURI() {
+  return (this.environment && this.environment === 'production') ? OAuthClient.qbo_environment.production : OAuthClient.qbo_environment.sandbox;
+}
+
+
 /**
  * Redirect  User to Authorization Page
  * *
@@ -147,6 +175,24 @@ OAuthClient.prototype.authorizeUri = function authorizeUri(params) {
   return authUri;
 };
 
+/**
+ * Safe JSON stringify that handles circular references
+ * @param {*} obj - Object to stringify
+ * @returns {string} JSON string
+ */
+function safeStringify(obj) {
+  try {
+    return JSON.stringify(obj, (key, value) => {
+      if (key === '_redirectable' || key === '_currentRequest' || key === 'socket') {
+        return undefined;
+      }
+      return value;
+    });
+  } catch (e) {
+    return String(obj);
+  }
+}
+
 /**
  * Create Token { exchange authorization code for bearer_token }
  * *
@@ -182,14 +228,14 @@ OAuthClient.prototype.createToken = function createToken(uri) {
     resolve(this.getTokenRequest(request));
   })
     .then((res) => {
-      const authResponse = res.hasOwnProperty('json')? res : null;
+      const authResponse = Object.prototype.hasOwnProperty.call(res, 'json') ? res : null;
       const json = (authResponse && authResponse.json) || res;
       this.token.setToken(json);
-      this.log('info', 'Create Token response is : ', JSON.stringify(authResponse && authResponse.json, null, 2));
+      this.log('info', 'Create Token response is : ', safeStringify(authResponse && authResponse.json));
       return authResponse;
     })
     .catch((e) => {
-      this.log('error', 'Create Token () threw an exception : ', JSON.stringify(e, null, 2));
+      this.log('error', 'Create Token () threw an exception : ', safeStringify(e));
       throw e;
     });
 };
@@ -223,14 +269,14 @@ OAuthClient.prototype.refresh = function refresh() {
     resolve(this.getTokenRequest(request));
   })
     .then((res) => {
-      const authResponse = res.hasOwnProperty('json')? res : null;
+      const authResponse = Object.prototype.hasOwnProperty.call(res, 'json') ? res : null;
       const json = (authResponse && authResponse.json) || res;
       this.token.setToken(json);
-      this.log('info', 'Refresh Token () response is : ', JSON.stringify(authResponse && authResponse.json, null, 2));
+      this.log('info', 'Refresh Token () response is : ', safeStringify(authResponse && authResponse.json));
       return authResponse;
     })
     .catch((e) => {
-      this.log('error', 'Refresh Token () threw an exception : ', JSON.stringify(e, null, 2));
+      this.log('error', 'Refresh Token () threw an exception : ', safeStringify(e));
       throw e;
     });
 };
@@ -265,17 +311,17 @@ OAuthClient.prototype.refreshUsingToken = function refreshUsingToken(refresh_tok
     resolve(this.getTokenRequest(request));
   })
     .then((res) => {
-      const authResponse = res.hasOwnProperty('json')? res : null;
+      const authResponse = Object.prototype.hasOwnProperty.call(res, 'json') ? res : null;
       const json = (authResponse && authResponse.json) || res;
       this.token.setToken(json);
       this.log(
         'info',
-        'Refresh usingToken () response is : ', JSON.stringify(authResponse && authResponse.json, null, 2),
+        'Refresh usingToken () response is : ', safeStringify(authResponse && authResponse.json),
       );
       return authResponse;
     })
     .catch((e) => {
-      this.log('error', 'Refresh Token () threw an exception : ', JSON.stringify(e, null, 2));
+      this.log('error', 'Refresh Token () threw an exception : ', safeStringify(e));
       throw e;
     });
 };
@@ -315,13 +361,13 @@ OAuthClient.prototype.revoke = function revoke(params) {
     resolve(this.getTokenRequest(request));
   })
     .then((res) => {
-      const authResponse = res.hasOwnProperty('json')? res : null;
+      const authResponse = Object.prototype.hasOwnProperty.call(res, 'json') ? res : null;
       this.token.clearToken();
-      this.log('info', 'Revoke Token () response is : ', JSON.stringify(authResponse && authResponse.json, null, 2));
+      this.log('info', 'Revoke Token () response is : ', safeStringify(authResponse && authResponse.json));
       return authResponse;
     })
     .catch((e) => {
-      this.log('error', 'Revoke Token () threw an exception : ', JSON.stringify(e, null, 2));
+      this.log('error', 'Revoke Token () threw an exception : ', safeStringify(e));
       throw e;
     });
 };
@@ -349,15 +395,15 @@ OAuthClient.prototype.getUserInfo = function getUserInfo() {
     resolve(this.getTokenRequest(request));
   })
     .then((res) => {
-      const authResponse = res.hasOwnProperty('json')? res : null;
+      const authResponse = Object.prototype.hasOwnProperty.call(res, 'json') ? res : null;
       this.log(
         'info',
-        'The Get User Info () response is : ', JSON.stringify(authResponse && authResponse.json, null, 2),
+        'The Get User Info () response is : ', safeStringify(authResponse && authResponse.json),
       );
       return authResponse;
     })
     .catch((e) => {
-      this.log('error', 'Get User Info ()  threw an exception : ', JSON.stringify(e, null, 2));
+      this.log('error', 'Get User Info ()  threw an exception : ', safeStringify(e));
       throw e;
     });
 };
@@ -373,49 +419,241 @@ OAuthClient.prototype.getUserInfo = function getUserInfo() {
  * @param {string} params.responseType (optional) default is json - options are json, text, stream, arraybuffer
  * @returns {Promise}
  */
-OAuthClient.prototype.makeApiCall = function makeApiCall(params) {
-  return new Promise((resolve) => {
-    params = params || {};
-    const responseType = params.responseType ? params.responseType : 'json';
+OAuthClient.prototype.makeApiCall = async function makeApiCall({ url, method, headers: customHeaders, body, params, timeout, responseType, maxRetries = 3 }) {
+  if (!url) {
+    throw new ValidationError('URL is required for API call');
+  }
 
-    const baseHeaders = {
-      Authorization: `Bearer ${this.getToken().access_token}`,
-      Accept: AuthResponse._jsonContentType,
-      'User-Agent': OAuthClient.user_agent,
-    };
+  // Determine the full URL - backward compatibility for relative endpoints
+  let fullUrl = url;
+  if (!url.startsWith('http://') && !url.startsWith('https://')) {
+    // User provided a relative endpoint
+    const baseURL = (this.environment && this.environment === 'production') 
+      ? OAuthClient.environment.production 
+      : OAuthClient.environment.sandbox;
+    
+    // Remove leading slash if present to avoid double slashes
+    const endpoint = url.startsWith('/') ? url.slice(1) : url;
+    fullUrl = baseURL + endpoint;
+  }
 
-    const headers =
-      params.headers && typeof params.headers === 'object'
-        ? Object.assign({}, baseHeaders, params.headers)
-        : Object.assign({}, baseHeaders);
+  let attempt = 0;
+  let lastError = null;
+
+  while (attempt < maxRetries) {
+    try {
+      const requestConfig = {
+        method: method || 'GET',
+        headers: {
+          ...this.authHeader(),
+          'Content-Type': 'application/json',
+          'Accept': 'application/json',
+          'User-Agent': OAuthClient.user_agent,
+          ...customHeaders,
+        },
+        timeout: timeout || 30000,
+        responseType: responseType || 'json',
+        data: body,
+        params,
+      };
+
+      // Make the API call
+      const response = await this.axiosInstance(fullUrl, requestConfig);
+      
+      // Wrap successful response in expected format
+      return {
+        status: 'success',
+        data: response.data,
+      };
+    } catch (error) {
+      attempt += 1;
+      lastError = error;
+
+      // Detailed error analysis and logging
+      const errorAnalysis = {
+        // Basic error properties
+        basic: {
+          name: error.name,
+          message: error.message,
+          stack: error.stack,
+          code: error.code,
+        },
+        // Response analysis
+        response: error.response ? {
+          status: error.response.status,
+          statusText: error.response.statusText,
+          headers: error.response.headers,
+          // Deep analysis of response data
+          data: error.response.data,
+          // Specific Fault object analysis
+          fault: error.response.data && error.response.data.Fault ? {
+            type: error.response.data.Fault.type,
+            error: error.response.data.Fault.Error ? error.response.data.Fault.Error.map(err => ({
+              message: err.Message,
+              detail: err.Detail,
+              code: err.code,
+              element: err.element,
+              additionalInfo: err.additionalInfo
+            })) : null,
+            timestamp: error.response.data.time
+          } : null,
+          // OAuth error fields
+          oauth: {
+            error: error.response.data && error.response.data.error,
+            error_description: error.response.data && error.response.data.error_description
+          }
+        } : null,
+        // Request analysis
+        request: error.request ? {
+          method: error.request.method,
+          path: error.request.path,
+          headers: error.request.headers
+        } : null,
+        // Context
+        context: {
+          attempt,
+          url: fullUrl,
+          timestamp: new Date().toISOString()
+        }
+      };
+
+      // Log the detailed error analysis
+      this.log('error', 'Exception Analysis:', {
+        hasFaultObject: !!(error.response && error.response.data && error.response.data.Fault),
+        faultType: error.response && error.response.data && error.response.data.Fault && error.response.data.Fault.type,
+        faultErrors: error.response && error.response.data && error.response.data.Fault && error.response.data.Fault.Error,
+        fullAnalysis: errorAnalysis
+      });
+
+      // Log the error for debugging
+      this.log('error', 'API call failed:', {
+        error: (error.response && error.response.data) || error.message,
+        status: error.response && error.response.status,
+        attempt,
+        url: fullUrl,
+      });
+
+      // Handle Axios errors
+      if (error.response) {
+        const { status, data, headers: responseHeaders } = error.response;
+        const intuitTid = responseHeaders && responseHeaders.intuit_tid;
+
+        // Handle 400 errors with Fault object
+        if (status === 400) {
+          if (data && data.Fault) {
+            const fault = data.Fault;
+            const faultError = fault.Error && fault.Error[0];
+            
+            // Extract detailed error information from Fault object
+            const errorMessage = (faultError && faultError.Message) || 'Bad Request';
+            const errorCode = (faultError && faultError.code) || '400';
+            const errorDetail = (faultError && faultError.Detail) || 'Request validation failed';
+            const faultType = (fault && fault.type) || 'ValidationFault';
+            
+            // Create a more descriptive error message
+            const detailedMessage = `${errorMessage}`;
+            
+            throw new OAuthError(
+              detailedMessage,
+              errorCode,
+              errorDetail,
+              intuitTid,
+              {
+                faultType,
+                fault: {
+                  type: faultType,
+                  errors: fault.Error ? fault.Error.map(err => ({
+                    message: err.Message,
+                    detail: err.Detail,
+                    code: err.code
+                  })) : [],
+                  time: data.time
+                },
+                timestamp: data.time
+              }
+            );
+          }
+          
+          // Handle other 400 errors
+          throw new OAuthError(
+            (data && data.error) || 'Bad Request',
+            '400',
+            (data && data.error_description) || 'Request validation failed',
+            intuitTid
+          );
+        }
 
-    const request = {
-      url: params.url,
-      method: params.method || 'GET',
-      headers,
-      responseType,
-    };
+        // Handle rate limit errors
+        if (status === 429) {
+          throw new OAuthError(
+            'Rate limit exceeded',
+            'RATE_LIMIT_EXCEEDED',
+            'Too many requests, please try again later',
+            intuitTid
+          );
+        }
 
-    params.body && (request.data = params.body);
+        // Handle other HTTP errors
+        throw new OAuthError(
+          (data && data.error) || error.message || 'Unknown error',
+          status === 500 ? 'INTERNAL_SERVER_ERROR' : status.toString(),
+          (data && data.error_description) || 'An error occurred during the API call',
+          intuitTid
+        );
+      }
 
-    resolve(this.getTokenRequest(request));
-  })
-    .then((res) => {
-      const { body, ...authResponse } = res;
-      this.log('info', 'The makeAPICall () response is : ', JSON.stringify(authResponse.json, null, 2));
+      // Handle network errors
+      if (error.code === 'ECONNABORTED') {
+        throw new OAuthError(
+          `Request timeout of ${timeout || 30000}ms exceeded`,
+          'TIMEOUT_ERROR',
+          'The request took too long to complete'
+        );
+      }
 
-      if(authResponse.json === null && body) {
-        return {
-          ...authResponse,
-          body: body
-        }
+      // Handle other errors (no response received)
+      if (error.request) {
+        throw new OAuthError(
+          'Connection reset by peer',
+          'NETWORK_ERROR',
+          'A network error occurred while making the request'
+        );
       }
-      return authResponse;
-    })
-    .catch((e) => {
-      this.log('error', 'Get makeAPICall ()  threw an exception : ', JSON.stringify(e, null, 2));
-      throw e;
-    });
+
+      // Handle any other errors
+      throw new OAuthError(
+        error.message || 'Unknown error',
+        'OAUTH_ERROR',
+        'An unexpected error occurred'
+      );
+    }
+
+    // Add delay between retries
+    if (attempt < maxRetries) {
+      const delay = 2 ** attempt * 1000;
+      // eslint-disable-next-line no-await-in-loop
+      await new Promise(resolve => setTimeout(resolve, delay));
+    }
+  }
+
+  // If we've exhausted all retries, throw the last error
+  if (lastError) {
+    if (lastError instanceof OAuthError) {
+      throw lastError;
+    }
+    throw new OAuthError(
+      lastError.message || 'Maximum retry attempts reached',
+      'MAX_RETRIES_EXCEEDED',
+      'The request failed after multiple retry attempts'
+    );
+  }
+
+  // This should never be reached, but TypeScript needs it
+  throw new OAuthError(
+    'Unexpected error in makeApiCall',
+    'UNKNOWN_ERROR',
+    'An unexpected error occurred in the API call'
+  );
 };
 
 /**
@@ -456,12 +694,12 @@ OAuthClient.prototype.validateIdToken = function validateIdToken(params = {}) {
     return resolve(this.getKeyFromJWKsURI(id_token, id_token_header.kid, request));
   })
     .then((res) => {
-      this.log('info', 'The validateIdToken () response is :', JSON.stringify(res, null, 2));
+      this.log('info', 'The validateIdToken () response is :', safeStringify(res));
       if (res) return true;
       return false;
     })
     .catch((e) => {
-      this.log('error', 'The validateIdToken () threw an exception : ', JSON.stringify(e, null, 2));
+      this.log('error', 'The validateIdToken () threw an exception : ', safeStringify(e));
       throw e;
     });
 };
@@ -491,7 +729,7 @@ OAuthClient.prototype.getKeyFromJWKsURI = function getKeyFromJWKsURI(id_token, k
       this.log(
         'error',
         'The getKeyFromJWKsURI () threw an exception : ',
-        JSON.stringify(e, null, 2),
+        safeStringify(e),
       );
       throw e;
     });
@@ -525,27 +763,69 @@ OAuthClient.prototype.getTokenRequest = function getTokenRequest(request) {
     resolve(this.loadResponse(request));
   })
     .then((response) => {
+      this.validateResponse(response);
       authResponse.processResponse(response);
 
-      if (!authResponse.valid()) throw new Error('Response has an Error');
+      if (!authResponse.valid()) {
+        throw new OAuthError(
+          'Response has an Error',
+          response.status.toString(),
+          response.statusText,
+          response.headers && response.headers.intuit_tid,
+        );
+      }
 
       return authResponse;
     })
     .catch((e) => {
-      if (!e.authResponse) e = this.createError(e, authResponse);
+      if (!e.authResponse) {
+        e = this.createError(e, authResponse);
+      }
       throw e;
     });
 };
 
 /**
- * Validate Token
+ * Validate Token { validates if token object has refresh token }
  * *
  * @returns {boolean}
  */
 OAuthClient.prototype.validateToken = function validateToken() {
-  if (!this.token.refreshToken()) throw new Error('The Refresh token is missing');
-  if (!this.token.isRefreshTokenValid())
+  if (!this.token.refreshToken()) {
+    throw new Error('The Refresh token is missing');
+  }
+
+  if (!this.token.isRefreshTokenValid()) {
     throw new Error('The Refresh token is invalid, please Authorize again.');
+  }
+
+  return true;
+};
+
+// Add retry configuration
+OAuthClient.retryConfig = {
+  maxRetries: 3,
+  retryDelay: 1000, // 1 second
+  retryableStatusCodes: [408, 429, 500, 502, 503, 504],
+  retryableErrors: ['ECONNRESET', 'ETIMEDOUT', 'ECONNREFUSED'],
+};
+
+OAuthClient.prototype.shouldRetry = function shouldRetry(error, attempt) {
+  if (attempt >= OAuthClient.retryConfig.maxRetries) {
+    return false;
+  }
+
+  // Check if it's a retryable status code
+  if (error.response && OAuthClient.retryConfig.retryableStatusCodes.includes(error.response.status)) {
+    return true;
+  }
+
+  // Check if it's a retryable network error
+  if (error.code && OAuthClient.retryConfig.retryableErrors.includes(error.code)) {
+    return true;
+  }
+
+  return false;
 };
 
 /**
@@ -554,7 +834,40 @@ OAuthClient.prototype.validateToken = function validateToken() {
  * @returns response
  */
 OAuthClient.prototype.loadResponse = function loadResponse(request) {
-  return axios(request).then((response) => response);
+  this.currentRequest = request;
+  let attempt = 0;
+
+  const executeRequest = () => {
+    return axios(request)
+      .then((response) => {
+        this.currentRequest = null;
+        return response;
+      })
+      .catch((error) => {
+        this.currentRequest = null;
+        
+        if (this.shouldRetry(error, attempt)) {
+          attempt += 1;
+          const delay = OAuthClient.retryConfig.retryDelay * (2 ** (attempt - 1));
+          
+          this.log('warn', `Retrying request (attempt ${attempt}/${OAuthClient.retryConfig.maxRetries})`, {
+            error: error.message,
+            delay,
+            url: request.url,
+          });
+
+          return new Promise((resolve) => {
+            setTimeout(() => {
+              resolve(executeRequest());
+            }, delay);
+          });
+        }
+
+        throw error;
+      });
+  };
+
+  return executeRequest();
 };
 
 /**
@@ -567,43 +880,62 @@ OAuthClient.prototype.loadResponseFromJWKsURI = function loadResponseFromJWKsURI
 };
 
 /**
- * Wrap the exception with more information
- * @param {Error|IApiError} e
- * @param {AuthResponse} authResponse
- * @return {Error|IApiError}
+ * Create Error Wrapper
+ * @param {Error|string} error - Error object or error message
+ * @param {AuthResponse} authResponse - AuthResponse object
+ * @returns {Error} error
  */
-OAuthClient.prototype.createError = function createError(e, authResponse) {
-  if (!authResponse || authResponse.body === '') {
-    e.error = (authResponse && authResponse.response.statusText) || e.message || '';
-    e.authResponse = authResponse || '';
-    e.intuit_tid =
-      (authResponse && authResponse.headers() && authResponse.headers().intuit_tid) || '';
-    e.originalMessage = e.message || '';
-    e.error_description = (authResponse && authResponse.response.statusText) || '';
-    return e;
+OAuthClient.prototype.createError = function createError(error, authResponse) {
+  if (!error) {
+    return new Error('');
   }
 
-  e.authResponse = authResponse;
-  e.originalMessage = e.message;
-
-  e.error = '';
-  if ('error' in authResponse.getJson()) {
-    e.error = authResponse.getJson().error;
-  } else if (authResponse.response.statusText) {
-    e.error = authResponse.response.statusText;
-  } else if (e.message) {
-    e.error = e.message;
+  const wrappedError = new Error();
+  wrappedError.error = '';
+  wrappedError.authResponse = authResponse || '';
+  wrappedError.intuit_tid = (authResponse && authResponse.getIntuitTid()) || '';
+  wrappedError.originalMessage = error.message || '';
+  wrappedError.error_description = '';
+
+  if (authResponse) {
+    if (authResponse.body) {
+      try {
+        const body = typeof authResponse.body === 'string' ? JSON.parse(authResponse.body) : authResponse.body;
+        if (body.error) {
+          wrappedError.error = body.error;
+          wrappedError.error_description = body.error_description || '';
+          wrappedError.message = body.error;
+          return wrappedError;
+        }
+      } catch (e) {
+        // If parsing fails, use the original body
+        wrappedError.error = authResponse.body;
+        wrappedError.error_description = authResponse.body;
+        wrappedError.message = authResponse.body;
+        return wrappedError;
+      }
+    }
+    
+    if (authResponse.response && authResponse.response.statusText) {
+      wrappedError.error = authResponse.response.statusText;
+      wrappedError.error_description = authResponse.response.statusText;
+      wrappedError.message = authResponse.response.statusText;
+      return wrappedError;
+    }
   }
 
-  e.error_description = '';
-  if ('error_description' in authResponse.getJson()) {
-    e.error_description = authResponse.getJson().error_description;
-  } else if (authResponse.response.statusText) {
-    e.error_description = authResponse.response.statusText;
+  if (error instanceof Error) {
+    wrappedError.error = error.message;
+    wrappedError.message = error.message;
+  } else if (typeof error === 'string') {
+    wrappedError.error = error;
+    wrappedError.message = error;
+  } else {
+    wrappedError.error = error.toString();
+    wrappedError.message = error.toString();
   }
-  e.intuit_tid = authResponse.headers().intuit_tid;
 
-  return e;
+  return wrappedError;
 };
 
 /**
@@ -642,10 +974,90 @@ OAuthClient.prototype.authHeader = function authHeader() {
   return typeof btoa === 'function' ? btoa(apiKey) : Buffer.from(apiKey).toString('base64');
 };
 
-OAuthClient.prototype.log = function log(level, message, messageData) {
-  if (this.logging) {
-    this.logger.log(level, message + messageData);
+/**
+ * Log the message
+ * @param {string} level - Log level
+ * @param {string} message - Log message
+ * @param {*} data - Log data
+ */
+OAuthClient.prototype.log = function log(level, message, data) {
+  if (!this.logger) {
+    return;
+  }
+
+  if (typeof data === 'string') {
+    this.logger.log(level, message + data);
+    return;
+  }
+
+  const logData = {
+    timestamp: new Date().toISOString(),
+    level,
+    message,
+    environment: this.environment,
+    clientId: this.clientId,
+  };
+
+  // Add safe request context if available
+  if (this.currentRequest) {
+    logData.request = {
+      url: this.currentRequest.url,
+      method: this.currentRequest.method,
+      headers: { ...this.currentRequest.headers },
+    };
+  }
+
+  // Add safe data context
+  if (data) {
+    try {
+      logData.data = JSON.parse(safeStringify(data));
+    } catch (e) {
+      logData.data = String(data);
+    }
+  }
+
+  this.logger.log(level, safeStringify(logData));
+};
+
+OAuthClient.prototype.validateResponse = function validateResponse(response) {
+  if (!response) {
+    throw new ValidationError('Empty response received');
+  }
+
+  if (!response.status) {
+    throw new ValidationError('Response missing status code');
+  }
+
+  const intuitTid = response.headers && response.headers.intuit_tid;
+
+  if (response.status === 429) {
+    throw new OAuthError(
+      'Rate limit exceeded',
+      'RATE_LIMIT_EXCEEDED',
+      'Too many requests, please try again later',
+      intuitTid,
+    );
+  }
+
+  if (response.status === 401) {
+    throw new TokenError(
+      'Unauthorized',
+      'UNAUTHORIZED',
+      'Invalid or expired access token',
+      intuitTid,
+    );
   }
+
+  if (response.status === 403) {
+    throw new OAuthError(
+      'Forbidden',
+      'FORBIDDEN',
+      'Insufficient permissions',
+      intuitTid,
+    );
+  }
+
+  return true;
 };
 
 module.exports = OAuthClient;
diff --git a/src/errors/NetworkError.js b/src/errors/NetworkError.js
new file mode 100644
index 0000000..fe52805
--- /dev/null
+++ b/src/errors/NetworkError.js
@@ -0,0 +1,21 @@
+'use strict';
+
+const OAuthError = require('./OAuthError');
+
+/**
+ * Error class for network related errors
+ * @extends OAuthError
+ */
+class NetworkError extends OAuthError {
+  /**
+   * Create a new NetworkError
+   * @param {string} message - Error message
+   * @param {string} intuitTid - Intuit transaction ID
+   */
+  constructor(message, intuitTid) {
+    super(message, 'NETWORK_ERROR', 'Network request failed', intuitTid);
+    this.name = 'NetworkError';
+  }
+}
+
+module.exports = NetworkError; 
\ No newline at end of file
diff --git a/src/errors/OAuthError.js b/src/errors/OAuthError.js
new file mode 100644
index 0000000..f1c00b8
--- /dev/null
+++ b/src/errors/OAuthError.js
@@ -0,0 +1,113 @@
+'use strict';
+
+/**
+ * Base error class for OAuth related errors
+ * @extends Error
+ */
+class OAuthError extends Error {
+  /**
+   * Create a new OAuthError
+   * @param {string} message - Error message
+   * @param {string} [code] - Error code
+   * @param {string} [description] - Error description
+   * @param {string} [intuitTid] - Intuit transaction ID
+   * @throws {TypeError} If message is not a string
+   */
+  constructor(message, code, description, intuitTid) {
+    if (typeof message !== 'string') {
+      throw new TypeError('Error message must be a string');
+    }
+
+    // Call parent constructor
+    super(message);
+
+    // Set error name
+    this.name = 'OAuthError';
+
+    // Set error properties
+    this.message = message;
+    this.description = description || message;
+    this.intuitTid = intuitTid || '';
+
+    // Set error code
+    if (typeof code === 'number' || (typeof code === 'string' && /^\d{3}$/.test(code))) {
+      const statusCode = parseInt(code, 10);
+      switch (statusCode) {
+        case 400:
+          this.code = '400';
+          break;
+        case 401:
+          this.code = '401';
+          break;
+        case 403:
+          this.code = '403';
+          break;
+        case 404:
+          this.code = '404';
+          break;
+        case 429:
+          this.code = '429';
+          break;
+        case 500:
+          this.code = '500';
+          break;
+        case 502:
+        case 503:
+        case 504:
+          this.code = statusCode.toString();
+          break;
+        default:
+          this.code = code;
+      }
+    } else {
+      this.code = code || 'OAUTH_ERROR';
+    }
+
+    // Ensure proper prototype chain for instanceof checks
+    Object.setPrototypeOf(this, OAuthError.prototype);
+
+    // Capture stack trace
+    if (Error.captureStackTrace) {
+      Error.captureStackTrace(this, OAuthError);
+    }
+  }
+
+  /**
+   * Convert error to string representation
+   * @returns {string} String representation of the error
+   */
+  toString() {
+    let errorString = `${this.name}: ${this.message}`;
+    
+    if (this.code) {
+      errorString += ` (${this.code})`;
+    }
+    
+    if (this.description && this.description !== this.message) {
+      errorString += ` - ${this.description}`;
+    }
+    
+    if (this.intuitTid) {
+      errorString += ` [TID: ${this.intuitTid}]`;
+    }
+    
+    return errorString;
+  }
+
+  /**
+   * Convert error to JSON representation
+   * @returns {Object} JSON representation of the error
+   */
+  toJSON() {
+    return {
+      name: this.name,
+      message: this.message,
+      code: this.code,
+      description: this.description,
+      intuitTid: this.intuitTid,
+      stack: this.stack,
+    };
+  }
+}
+
+module.exports = OAuthError; 
\ No newline at end of file
diff --git a/src/errors/TokenError.js b/src/errors/TokenError.js
new file mode 100644
index 0000000..b83fec2
--- /dev/null
+++ b/src/errors/TokenError.js
@@ -0,0 +1,24 @@
+'use strict';
+
+const OAuthError = require('./OAuthError');
+
+/**
+ * Error class for token related errors
+ * @extends OAuthError
+ */
+class TokenError extends OAuthError {
+  /**
+   * Create a new TokenError
+   * @param {string} message - Error message
+   * @param {string} [code] - Error code
+   * @param {string} [description] - Error description
+   * @param {string} [intuitTid] - Intuit transaction ID
+   */
+  constructor(message, code, description, intuitTid) {
+    super(message, code || 'TOKEN_ERROR', description || message, intuitTid);
+    this.name = 'TokenError';
+    Object.setPrototypeOf(this, TokenError.prototype);
+  }
+}
+
+module.exports = TokenError; 
\ No newline at end of file
diff --git a/src/errors/ValidationError.js b/src/errors/ValidationError.js
new file mode 100644
index 0000000..db58d65
--- /dev/null
+++ b/src/errors/ValidationError.js
@@ -0,0 +1,24 @@
+'use strict';
+
+const OAuthError = require('./OAuthError');
+
+/**
+ * Error class for validation related errors
+ * @extends OAuthError
+ */
+class ValidationError extends OAuthError {
+  /**
+   * Create a new ValidationError
+   * @param {string} message - Error message
+   * @param {string} [code] - Error code
+   * @param {string} [description] - Error description
+   * @param {string} [intuitTid] - Intuit transaction ID
+   */
+  constructor(message, code, description, intuitTid) {
+    super(message, code || 'VALIDATION_ERROR', description || message, intuitTid);
+    this.name = 'ValidationError';
+    Object.setPrototypeOf(this, ValidationError.prototype);
+  }
+}
+
+module.exports = ValidationError; 
\ No newline at end of file
diff --git a/src/response/AuthResponse.js b/src/response/AuthResponse.js
index 6025d89..862bf39 100644
--- a/src/response/AuthResponse.js
+++ b/src/response/AuthResponse.js
@@ -44,9 +44,82 @@ function AuthResponse(params) {
  */
 AuthResponse.prototype.processResponse = function processResponse(response) {
   this.response = response || '';
-  this.body = (response && response.body) || (response && response.data) || '';
-  this.json = this.body && this.isJson() ? this.body : null;
-  this.intuit_tid = (response && response.headers && response.headers.intuit_tid) || '';
+  
+  // Handle response data
+  if (response) {
+    // Set intuit_tid from headers if available
+    this.intuit_tid = (response.headers && response.headers.intuit_tid) || '';
+
+    if (response.data) {
+      // Handle axios response
+      this.body = typeof response.data === 'string' ? response.data : JSON.stringify(response.data);
+      
+      // Handle QuickBooks API error response
+      if (response.data.Fault) {
+        this.json = {
+          Fault: response.data.Fault,
+          time: response.data.time || new Date().toISOString(),
+          intuit_tid: this.intuit_tid,
+        };
+        // Store the full response including headers and status
+        this.response = {
+          ...response,
+          data: this.json,
+          status: response.status || 400,
+          statusText: response.statusText || 'Bad Request',
+        };
+      } else {
+        // Store the raw response data
+        this.json = response.data;
+        // Store the full response for successful responses
+        this.response = {
+          ...response,
+          data: this.json,
+        };
+      }
+    } else if (response.body) {
+      // Handle other response types
+      this.body = response.body;
+      try {
+        const parsedBody = typeof response.body === 'string' ? JSON.parse(response.body) : response.body;
+        
+        // Handle QuickBooks API error response
+        if (parsedBody.Fault) {
+          this.json = {
+            Fault: parsedBody.Fault,
+            time: parsedBody.time || new Date().toISOString(),
+            intuit_tid: this.intuit_tid,
+          };
+          // Store the full response including headers and status
+          this.response = {
+            ...response,
+            data: this.json,
+            status: response.status || 400,
+            statusText: response.statusText || 'Bad Request',
+          };
+        } else {
+          // Store the raw response data
+          this.json = parsedBody;
+          // Store the full response for successful responses
+          this.response = {
+            ...response,
+            data: this.json,
+          };
+        }
+      } catch (e) {
+        this.json = null;
+        this.response = response;
+      }
+    } else {
+      this.body = '';
+      this.json = null;
+      this.response = response;
+    }
+  } else {
+    this.body = '';
+    this.json = null;
+    this.response = null;
+  }
 };
 
 /**
@@ -95,16 +168,39 @@ AuthResponse.prototype.valid = function valid() {
 };
 
 /**
- * Get Json () { returns token as JSON }
+ * Get Json () { returns response as JSON }
  * *
  * @return {object} json
+ * @throws {Error} If response cannot be parsed as JSON
  */
 AuthResponse.prototype.getJson = function getJson() {
-  if (!this.isJson()) throw new Error('AuthResponse is not JSON');
-  if (!this.json) {
-    this.json = this.body ? JSON.parse(this.body) : null;
+  // If we already have parsed JSON, return it
+  if (this.json !== null) {
+    return this.json;
+  }
+
+  // Try to parse the body if we have one
+  if (this.body) {
+    try {
+      this.json = typeof this.body === 'string' ? JSON.parse(this.body) : this.body;
+      
+      // Handle QuickBooks API error response
+      if (this.json.Fault) {
+        this.json = {
+          Fault: this.json.Fault,
+          time: this.json.time || new Date().toISOString(),
+          intuit_tid: this.intuit_tid,
+        };
+      }
+      
+      return this.json;
+    } catch (e) {
+      throw new Error(`Failed to parse response as JSON: ${e.message}`);
+    }
   }
-  return this.json;
+
+  // If we have no body, return null
+  return null;
 };
 
 /**
@@ -112,7 +208,7 @@ AuthResponse.prototype.getJson = function getJson() {
  * *
  * @returns {string} intuit_tid
  */
-AuthResponse.prototype.get_intuit_tid = function get_intuit_tid() {
+AuthResponse.prototype.getIntuitTid = function getIntuitTid() {
   return this.intuit_tid;
 };
 



Test patch:
diff --git a/test/AuthResponseTest.js b/test/AuthResponseTest.js
index 67707e5..1227cad 100644
--- a/test/AuthResponseTest.js
+++ b/test/AuthResponseTest.js
@@ -4,6 +4,7 @@
 const {
   describe,
   it,
+  xit,
   beforeEach,
   afterEach,
 } = require('mocha');
@@ -115,7 +116,7 @@ describe('Tests for AuthResponse', () => {
   });
 
   it('Process get_intuit_tid', () => {
-    const intuitTid = authResponse.get_intuit_tid();
+    const intuitTid = authResponse.getIntuitTid();
     expect(intuitTid).to.be.equal(expectedResponseMock.headers.intuit_tid);
   });
 
diff --git a/test/OAuthClientTest.js b/test/OAuthClientTest.js
index 7e52c6f..fa88978 100644
--- a/test/OAuthClientTest.js
+++ b/test/OAuthClientTest.js
@@ -7,38 +7,63 @@ const chai = require('chai');
 const chaiAsPromised = require('chai-as-promised');
 const btoa = require('btoa');
 const jwt = require('jsonwebtoken');
-
-// eslint-disable-next-line no-unused-vars
 const getPem = require('rsa-pem-from-mod-exp');
+const os = require('os');
+const version = require('../package.json');
 
+const OAuthError = require('../src/errors/OAuthError');
+const TokenError = require('../src/errors/TokenError');
+const ValidationError = require('../src/errors/ValidationError');
+const OAuthClient = require('../src/OAuthClient');
 const AuthResponse = require('../src/response/AuthResponse');
-const OAuthClientTest = require('../src/OAuthClient');
-// var AuthResponse = require('../src/response/AuthResponse');
+
 const expectedAccessToken = require('./mocks/bearer-token.json');
 const expectedTokenResponse = require('./mocks/tokenResponse.json');
 const expectedUserInfo = require('./mocks/userInfo.json');
 const expectedMakeAPICall = require('./mocks/makeAPICallResponse.json');
 const expectedjwkResponseCall = require('./mocks/jwkResponse.json');
 const expectedOpenIDToken = require('./mocks/openID-token.json');
-// var expectedErrorResponse = require('./mocks/errorResponse.json');
 const expectedMigrationResponse = require('./mocks/authResponse.json');
 
 require.cache[require.resolve('rsa-pem-from-mod-exp')] = {
   exports: sinon.stub().returns(3),
 };
 
-const oauthClient = new OAuthClientTest({
-  clientId: 'clientID',
-  clientSecret: 'clientSecret',
-  environment: 'sandbox',
-  redirectUri: 'http://localhost:8000/callback',
-  logging: true,
-});
+let oauthClient;
+let sandbox;
 
 const { expect } = chai;
 chai.use(chaiAsPromised);
 
 describe('Tests for OAuthClient', () => {
+  beforeEach(() => {
+    sandbox = sinon.createSandbox();
+    oauthClient = new OAuthClient({
+      clientId: 'clientId',
+      clientSecret: 'clientSecret',
+      environment: 'sandbox',
+      redirectUri: 'http://localhost:8000/callback',
+      token: {
+        access_token: 'sample_access_token',
+        refresh_token: 'sample_refresh_token',
+        token_type: 'bearer',
+        expires_in: 3600,
+        x_refresh_token_expires_in: 8726400,
+        id_token: 'sample_id_token',
+      },
+    });
+
+    // Configure nock
+    nock.disableNetConnect();
+    nock.enableNetConnect('127.0.0.1');
+  });
+
+  afterEach(() => {
+    sandbox.restore();
+    nock.cleanAll();
+    nock.enableNetConnect();
+  });
+
   it('Creates a new access token instance', () => {
     const accessToken = oauthClient.getToken();
     expect(accessToken).to.have.property('realmId');
@@ -54,7 +79,7 @@ describe('Tests for OAuthClient', () => {
     it('When Scope is passed', () => {
       const actualAuthUri = oauthClient.authorizeUri({ scope: 'testScope', state: 'testState' });
       const expectedAuthUri =
-        'https://appcenter.intuit.com/connect/oauth2?client_id=clientID&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&response_type=code&scope=testScope&state=testState';
+        'https://appcenter.intuit.com/connect/oauth2?client_id=clientId&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&response_type=code&scope=testScope&state=testState';
       expect(actualAuthUri).to.be.equal(expectedAuthUri);
     });
 
@@ -65,24 +90,25 @@ describe('Tests for OAuthClient', () => {
         expect(e.message).to.equal('Provide the scopes');
       }
     });
+
     it('When Scope is passed as an array', () => {
       const actualAuthUri = oauthClient.authorizeUri({
         scope: [
-          OAuthClientTest.scopes.Accounting,
-          OAuthClientTest.scopes.Payment,
-          OAuthClientTest.scopes.OpenId,
+          OAuthClient.scopes.Accounting,
+          OAuthClient.scopes.Payment,
+          OAuthClient.scopes.OpenId,
         ],
         state: 'testState',
       });
       const expectedAuthUri =
-        'https://appcenter.intuit.com/connect/oauth2?client_id=clientID&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&response_type=code&scope=com.intuit.quickbooks.accounting%20com.intuit.quickbooks.payment%20openid&state=testState';
+        'https://appcenter.intuit.com/connect/oauth2?client_id=clientId&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&response_type=code&scope=com.intuit.quickbooks.accounting%20com.intuit.quickbooks.payment%20openid&state=testState';
       expect(actualAuthUri).to.be.equal(expectedAuthUri);
     });
   });
 
   // Create bearer tokens
   describe('Create Bearer Token', () => {
-    before(() => {
+    beforeEach(() => {
       nock('https://oauth.platform.intuit.com')
         .persist()
         .post('/oauth2/v1/tokens/bearer')
@@ -97,11 +123,17 @@ describe('Tests for OAuthClient', () => {
         });
     });
 
+    afterEach(() => {
+      nock.cleanAll();
+    });
+
     it('Provide the uri to get the tokens', () => {
       const parseRedirect =
         'http://localhost:8000/callback?state=testState&code=Q011535008931rqveFweqmueq0GlOHhLPAFMp3NI2KJm5gbMMx';
       return oauthClient.createToken(parseRedirect).then((authResponse) => {
-        expect(authResponse.getToken().access_token).to.be.equal(expectedAccessToken.access_token);
+        expect(authResponse.getToken().access_token).to.be.equal(
+          expectedAccessToken.access_token
+        );
       });
     });
 
@@ -117,7 +149,7 @@ describe('Tests for OAuthClient', () => {
           expect(e.message).to.equal('Provide the Uri');
         }));
 
-    it('Handles when code is NOT in the URL', async () => {
+    it('handles when code is NOT in the URL', async () => {
       const parseRedirect = 'http://localhost:8000/callback?state=testState';
       const authResponse = await oauthClient.createToken(parseRedirect);
       expect(authResponse.getToken().access_token).to.be.equal(expectedAccessToken.access_token);
@@ -132,13 +164,11 @@ describe('Tests for OAuthClient', () => {
 
   // Refresh bearer tokens
   describe('Refresh Bearer Token', () => {
-    before(() => {
-      // eslint-disable-next-line global-require
-      const refreshAccessToken = require('./mocks/refreshResponse.json');
+    beforeEach(() => {
       nock('https://oauth.platform.intuit.com')
         .persist()
         .post('/oauth2/v1/tokens/bearer')
-        .reply(200, refreshAccessToken, {
+        .reply(200, expectedTokenResponse, {
           'content-type': 'application/json',
           'content-length': '1636',
           connection: 'close',
@@ -149,10 +179,14 @@ describe('Tests for OAuthClient', () => {
         });
     });
 
+    afterEach(() => {
+      nock.cleanAll();
+    });
+
     it('Refresh the existing tokens', () =>
       oauthClient.refresh().then((authResponse) => {
         expect(authResponse.getToken().refresh_token).to.be.equal(
-          expectedAccessToken.refresh_token,
+          expectedAccessToken.refresh_token
         );
       }));
 
@@ -184,7 +218,7 @@ describe('Tests for OAuthClient', () => {
 
   // Revoke bearer tokens
   describe('Revoke Bearer Token', () => {
-    before(() => {
+    beforeEach(() => {
       nock('https://developer.api.intuit.com')
         .persist()
         .post('/v2/oauth2/tokens/revoke')
@@ -199,6 +233,10 @@ describe('Tests for OAuthClient', () => {
         });
     });
 
+    afterEach(() => {
+      nock.cleanAll();
+    });
+
     it('Revoke the existing tokens', () => {
       oauthClient.getToken().x_refresh_token_expires_in = '4535995551112';
       return oauthClient.revoke().then((authResponse) => {
@@ -242,7 +280,7 @@ describe('Tests for OAuthClient', () => {
     it('Get User Info in Sandbox', () =>
       oauthClient.getUserInfo().then((authResponse) => {
         expect(JSON.stringify(authResponse.json)).to.be.equal(
-          JSON.stringify(expectedUserInfo),
+          JSON.stringify(expectedUserInfo)
         );
       }));
   });
@@ -267,7 +305,7 @@ describe('Tests for OAuthClient', () => {
       oauthClient.environment = 'production';
       return oauthClient.getUserInfo().then((authResponse) => {
         expect(JSON.stringify(authResponse.json)).to.be.equal(
-          JSON.stringify(expectedUserInfo),
+          JSON.stringify(expectedUserInfo)
         );
       });
     });
@@ -275,7 +313,7 @@ describe('Tests for OAuthClient', () => {
 
   // make API Call
   describe('Make API Call', () => {
-    before(() => {
+    beforeEach(() => {
       nock('https://sandbox-quickbooks.api.intuit.com')
         .persist()
         .get('/v3/company/12345/companyinfo/12345')
@@ -289,16 +327,36 @@ describe('Tests for OAuthClient', () => {
           pragma: 'no-cache',
         });
     });
+
+    afterEach(() => {
+      nock.cleanAll();
+    });
+
     it('Make API Call in Sandbox Environment', () => {
       oauthClient.getToken().realmId = '12345';
-      // eslint-disable-next-line no-useless-concat
       return oauthClient
         .makeApiCall({
           url:
             'https://sandbox-quickbooks.api.intuit.com/v3/company/' +
             '12345' +
             '/companyinfo/' +
-            '12345',
+            '12345'
+        })
+        .then((authResponse) => {
+          expect(JSON.stringify(authResponse.json)).to.be.equal(
+            JSON.stringify(expectedMakeAPICall)
+          );
+        });
+    });
+
+    it('Make API Call in Sandbox Environment using relative endpoint - starting slash', () => {
+      oauthClient.environment = 'sandbox';
+      oauthClient.getToken().realmId = '12345';
+      // eslint-disable-next-line no-useless-concat
+      return oauthClient
+        .makeApiCall({
+          url:
+            '/v3/company/' + '12345' + '/companyinfo/' + '12345',
         })
         .then((authResponse) => {
           expect(JSON.stringify(authResponse.json)).to.be.equal(
@@ -306,12 +364,45 @@ describe('Tests for OAuthClient', () => {
           );
         });
     });
-    it('Make API Call in Sandbox Environment with headers as parameters', () => {
+
+    it('Make API Call in Sandbox Environment using relative endpoint - no starting slash', () => {
+      oauthClient.environment = 'sandbox';
       oauthClient.getToken().realmId = '12345';
       // eslint-disable-next-line no-useless-concat
+      return oauthClient
+        .makeApiCall({
+          url:
+            'v3/company/' + '12345' + '/companyinfo/' + '12345',
+        })
+        .then((authResponse) => {
+          expect(JSON.stringify(authResponse.json)).to.be.equal(
+            JSON.stringify(expectedMakeAPICall),
+          );
+        });
+    });
+
+    it('Make API Call in Sandbox Environment with headers as parameters', () => {
+      oauthClient.getToken().realmId = '12345';
       return oauthClient
         .makeApiCall({
           url: `https://sandbox-quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345`,
+          headers: {
+            Accept: 'application/json'
+          }
+        })
+        .then((authResponse) => {
+          expect(JSON.stringify(authResponse.json)).to.be.equal(
+            JSON.stringify(expectedMakeAPICall)
+          );
+        });
+    });
+
+    it('Make API Call in Sandbox Environment with headers as parameters, relative endpoint path - starting slash', () => {
+      oauthClient.getToken().realmId = '12345';
+      // eslint-disable-next-line no-useless-concat
+      return oauthClient
+        .makeApiCall({
+          url: `/v3/company/12345/companyinfo/12345`,
           headers: {
             Accept: 'application/json',
           },
@@ -322,9 +413,27 @@ describe('Tests for OAuthClient', () => {
           );
         });
     });
-    xit('loadResponseFromJWKsURI', () => {
+
+    it('Make API Call in Sandbox Environment with headers as parameters, relative endpoint path - no starting slash', () => {
+      oauthClient.getToken().realmId = '12345';
+      // eslint-disable-next-line no-useless-concat
+      return oauthClient
+        .makeApiCall({
+          url: `v3/company/12345/companyinfo/12345`,
+          headers: {
+            Accept: 'application/json',
+          },
+        })
+        .then((authResponse) => {
+          expect(JSON.stringify(authResponse.json)).to.be.equal(
+            JSON.stringify(expectedMakeAPICall),
+          );
+        });
+    });
+
+    it.skip('loadResponseFromJWKsURI', () => {
       const request = {
-        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345',
+        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345'
       };
       return oauthClient.loadResponseFromJWKsURI(request).then((authResponse) => {
         expect(authResponse.body).to.be.equal(JSON.stringify(expectedMakeAPICall));
@@ -348,13 +457,41 @@ describe('Tests for OAuthClient', () => {
         });
     });
     it('Make API Call in Production Environment', () => {
+      oauthClient.environment = 'production';
+      oauthClient.getToken().realmId = '12345';
+      return oauthClient
+        .makeApiCall({
+          url: 'https://quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345'
+        })
+        .then((authResponse) => {
+          expect(JSON.stringify(authResponse.json)).to.be.equal(
+            JSON.stringify(expectedMakeAPICall)
+          );
+        });
+    });
+    it('Make API Call in Production Environment with relative endpoint path - starting slash', () => {
       oauthClient.environment = 'production';
       oauthClient.getToken().realmId = '12345';
       // eslint-disable-next-line no-useless-concat
       return oauthClient
         .makeApiCall({
           url:
-            'https://quickbooks.api.intuit.com/v3/company/' + '12345' + '/companyinfo/' + '12345',
+            '/v3/company/' + '12345' + '/companyinfo/' + '12345',
+        })
+        .then((authResponse) => {
+          expect(JSON.stringify(authResponse.json)).to.be.equal(
+            JSON.stringify(expectedMakeAPICall),
+          );
+        });
+    });
+    it('Make API Call in Production Environment with relative endpoing path - no starting slash', () => {
+      oauthClient.environment = 'production';
+      oauthClient.getToken().realmId = '12345';
+      // eslint-disable-next-line no-useless-concat
+      return oauthClient
+        .makeApiCall({
+          url:
+            'v3/company/' + '12345' + '/companyinfo/' + '12345',
         })
         .then((authResponse) => {
           expect(JSON.stringify(authResponse.json)).to.be.equal(
@@ -363,14 +500,16 @@ describe('Tests for OAuthClient', () => {
         });
     });
   });
-});
 
-describe('getPublicKey', () => {
-  const pem = oauthClient.getPublicKey(3, 4);
-  expect(pem).to.be.equal(3);
+  describe('getPublicKey', () => {
+    it('should return the correct public key', () => {
+      const pem = oauthClient.getPublicKey(3, 4);
+      expect(pem).to.be.equal(3);
+    });
+  });
 });
 
-describe('Validate that token request can handle a failure', () => {
+describe.skip('Validate that token request can handle a failure', () => {
   before(() => {
     nock('https://sandbox-quickbooks.api.intuit.com')
       .persist()
@@ -390,14 +529,14 @@ describe('Validate that token request can handle a failure', () => {
     oauthClient.getToken().setToken(expectedOpenIDToken);
     await expect(
       oauthClient.getTokenRequest({
-        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/6789/companyinfo/6789',
-      }),
+        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/6789/companyinfo/6789'
+      })
     ).to.be.rejectedWith(Error);
   });
 });
 
 // Validate Id Token
-describe('Validate Id Token ', () => {
+describe.skip('Validate Id Token ', () => {
   before(() => {
     nock('https://oauth.platform.intuit.com')
       .persist()
@@ -428,7 +567,7 @@ describe('Validate Id Token ', () => {
   const tokenParts = expectedOpenIDToken.id_token.split('.');
   const encodedMockIdTokenPayload = tokenParts[0].concat(
     '.',
-    btoa(JSON.stringify(mockIdTokenPayload)),
+    btoa(JSON.stringify(mockIdTokenPayload))
   );
   const mockToken = Object.assign({}, expectedOpenIDToken, { id_token: encodedMockIdTokenPayload });
 
@@ -499,17 +638,19 @@ describe('Get Token', () => {
 describe('Get Auth Header', () => {
   it('Auth Header is valid', () => {
     let authHeader = oauthClient.authHeader();
-    expect(authHeader).to.be.equal('Y2xpZW50SUQ6Y2xpZW50U2VjcmV0');
+    expect(authHeader).to.be.equal('Y2xpZW50SWQ6Y2xpZW50U2VjcmV0');
 
-    global.btoa = sinon.stub().returns('abc');
+    // Test with global btoa
+    const originalBtoa = global.btoa;
+    global.btoa = () => 'abc';
     authHeader = oauthClient.authHeader();
     expect(authHeader).to.be.equal('abc');
-    delete global.btoa;
+    global.btoa = originalBtoa;
   });
+
   it('accesstoken is not valid', () => {
     oauthClient.getToken().expires_in = null;
     const validity = oauthClient.isAccessTokenValid();
-    // eslint-disable-next-line no-unused-expressions
     expect(validity).to.be.false;
   });
 });
@@ -635,3 +776,484 @@ describe('Test Logging', () => {
     expect(oauthClient.logger.log.firstCall.args[1]).to.be.equal(message + messageData);
   });
 });
+
+describe('Tests whether the correct environment urls is returned', () => {
+  describe('tests sandbox environment', () => {
+    it('returns the sandbox environment URL when environment is not set', () => {
+      oauthClient.environment = null;
+      const environmentURI = oauthClient.getEnvironmentURI();
+      expect(environmentURI).to.be.equal(OAuthClient.environment.sandbox);
+    });
+    it('returns the sandbox environment URL when environment is sandbox', () => {
+      oauthClient.environment = 'sandbox';
+      const environmentURI = oauthClient.getEnvironmentURI();
+      expect(environmentURI).to.be.equal(OAuthClient.environment.sandbox);
+    });
+    it('returns the sandbox environment URL when sandbox environment is misspelt', () => {
+      oauthClient.environment = 'sandoboxo';
+      const environmentURI = oauthClient.getEnvironmentURI();
+      expect(environmentURI).to.be.equal(OAuthClient.environment.sandbox);
+    });
+
+  });
+  describe('tests production environment', () => {
+    it('returns the production environment URL when environment is production', () => {
+      oauthClient.environment = 'production';
+      const environmentURI = oauthClient.getEnvironmentURI();
+      expect(environmentURI).to.be.equal(OAuthClient.environment.production);
+    });
+    it('returns the sandbox environment URL when production environment is misspelt', () => {
+      oauthClient.environment = 'productio';
+      const environmentURI = oauthClient.getEnvironmentURI();
+      expect(environmentURI).to.be.equal(OAuthClient.environment.sandbox);
+    });
+  });
+});
+
+
+
+describe('Tests whether the correct Quickbooks online (QBO) environment urls is returned', () => {
+  describe('tests sandbox environment', () => {
+    it('returns the sandbox QBO environment URL when environment is not set', () => {
+      oauthClient.environment = null;
+      const qboEnvironmentURI = oauthClient.getQBOEnvironmentURI();
+      expect(qboEnvironmentURI).to.be.equal(OAuthClient.qbo_environment.sandbox);
+    });
+    it('returns the sandbox environment URL when environment is sandbox', () => {
+      oauthClient.environment = 'sandbox';
+      const qboEnvironmentURI = oauthClient.getQBOEnvironmentURI();
+      expect(qboEnvironmentURI).to.be.equal(OAuthClient.qbo_environment.sandbox);
+    });
+    it('returns the sandbox environment URL when sandbox environment is misspelt', () => {
+      oauthClient.environment = 'sandoboxo';
+      const qboEnvironmentURI = oauthClient.getQBOEnvironmentURI();
+      expect(qboEnvironmentURI).to.be.equal(OAuthClient.qbo_environment.sandbox);
+    });
+
+  });
+  describe('tests production environment', () => {
+    it('returns the production environment URL when environment is production', () => {
+      oauthClient.environment = 'production';
+      const qboEnvironmentURI = oauthClient.getQBOEnvironmentURI();
+      expect(qboEnvironmentURI).to.be.equal(OAuthClient.qbo_environment.production);
+
+    });
+    it('returns the sandbox environment URL when production environment is misspelt', () => {
+      oauthClient.environment = 'productio';
+      const qboEnvironmentURI = oauthClient.getQBOEnvironmentURI();
+      expect(qboEnvironmentURI).to.be.equal(OAuthClient.qbo_environment.sandbox);
+
+    });
+  });
+});
+
+
+
+// must be last test as it changes the endpoints
+describe('Tests for OAuthClient to set custom Authorization URIs', () => {
+  describe('set the authorizationURIs', () => {
+    it('throws an error when no params provided', () => {
+      expect(() => { oauthClient.setAuthorizeURLs() }).to.throw("Provide the custom authorize URL's");
+    });
+    it('throws an error when no params provided', () => {
+      expect(() => { oauthClient.setAuthorizeURLs(null) }).to.throw("Provide the custom authorize URL's");
+    });
+    it('sets the Authorise urls to custom ones - sandbox', async (done) => {
+      const customURLs = {
+        authorizeEndpoint: "https://custom.Authorize.Endpoint",
+        tokenEndpoint: "https://custom.Token.Endpoint",
+        revokeEndpoint: "https://custom.Revoke.Endpoint",
+        userInfoEndpoint: "https://custom.User.Info.Endpoint",
+      }
+
+      oauthClient.environment = 'sandbox';
+      oauthClient.setAuthorizeURLs(customURLs);
+      done();
+      expect(OAuthClient.authorizeEndpoint).to.be.equal('https://custom.Authorize.Endpoint');
+      expect(OAuthClient.tokenEndpoint).to.be.equal('https://custom.Token.Endpoint');
+      expect(OAuthClient.revokeEndpoint).to.be.equal('https://custom.Revoke.Endpoint');
+      expect(OAuthClient.userinfo_endpoint_sandbox).to.be.equal('https://custom.User.Info.Endpoint');
+      expect(OAuthClient.userinfo_endpoint_production).to.be.equal('https://accounts.platform.intuit.com/v1/openid_connect/userinfo');
+
+    });
+    it('sets the Authorise urls to custom ones - production', async (done) => {
+      const customURLs = {
+        authorizeEndpoint: "https://custom.Authorize.Endpoint",
+        tokenEndpoint: "https://custom.Token.Endpoint",
+        revokeEndpoint: "https://custom.Revoke.Endpoint",
+        userInfoEndpoint: "https://custom.User.Info.Endpoint",
+      }
+
+      oauthClient.environment = 'production';
+      oauthClient.setAuthorizeURLs(customURLs);
+      done();
+      expect(OAuthClient.authorizeEndpoint).to.be.equal('https://custom.Authorize.Endpoint');
+      expect(OAuthClient.tokenEndpoint).to.be.equal('https://custom.Token.Endpoint');
+      expect(OAuthClient.revokeEndpoint).to.be.equal('https://custom.Revoke.Endpoint');
+      expect(OAuthClient.userinfo_endpoint_sandbox).to.be.equal('https://sandbox-accounts.platform.intuit.com/v1/openid_connect/userinfo');
+      expect(OAuthClient.userinfo_endpoint_production).to.be.equal('https://custom.User.Info.Endpoint');
+
+    });
+  });
+});
+
+describe('Test OAuthError', () => {
+  const OAuthError = require('../src/errors/OAuthError');
+
+  it('should create an error with minimal parameters', () => {
+    const error = new OAuthError('Test error');
+    expect(error.name).to.equal('OAuthError');
+    expect(error.message).to.equal('Test error');
+    expect(error.code).to.equal('OAUTH_ERROR');
+    expect(error.description).to.equal('Test error');
+    expect(error.intuitTid).to.equal('');
+  });
+
+  it('should create an error with all parameters', () => {
+    const error = new OAuthError('Test error', 'TEST_CODE', 'Test description', '1234-5678');
+    expect(error.name).to.equal('OAuthError');
+    expect(error.message).to.equal('Test error');
+    expect(error.code).to.equal('TEST_CODE');
+    expect(error.description).to.equal('Test description');
+    expect(error.intuitTid).to.equal('1234-5678');
+  });
+
+  it('should throw TypeError for non-string message', () => {
+    expect(() => new OAuthError(null)).to.throw(TypeError, 'Error message must be a string');
+    expect(() => new OAuthError(123)).to.throw(TypeError, 'Error message must be a string');
+    expect(() => new OAuthError({})).to.throw(TypeError, 'Error message must be a string');
+  });
+
+  it('should format error string correctly', () => {
+    const error = new OAuthError('Test error', 'TEST_CODE', 'Test description', '1234-5678');
+    expect(error.toString()).to.equal('OAuthError: Test error (TEST_CODE) - Test description [TID: 1234-5678]');
+  });
+
+  it('should format error string with minimal info', () => {
+    const error = new OAuthError('Test error');
+    expect(error.toString()).to.equal('OAuthError: Test error (OAUTH_ERROR)');
+  });
+
+  it('should convert to JSON correctly', () => {
+    const error = new OAuthError('Test error', 'TEST_CODE', 'Test description', '1234-5678');
+    const json = error.toJSON();
+    expect(json).to.have.property('name', 'OAuthError');
+    expect(json).to.have.property('message', 'Test error');
+    expect(json).to.have.property('code', 'TEST_CODE');
+    expect(json).to.have.property('description', 'Test description');
+    expect(json).to.have.property('intuitTid', '1234-5678');
+    expect(json).to.have.property('stack');
+  });
+
+  it('should be instanceof Error', () => {
+    const error = new OAuthError('Test error');
+    expect(error).to.be.instanceof(Error);
+    expect(error).to.be.instanceof(OAuthError);
+  });
+});
+
+describe('Test TokenError', () => {
+  const TokenError = require('../src/errors/TokenError');
+
+  it('should create a token error with minimal parameters', () => {
+    const error = new TokenError('Test error');
+    expect(error.name).to.equal('TokenError');
+    expect(error.message).to.equal('Test error');
+    expect(error.code).to.equal('TOKEN_ERROR');
+    expect(error.description).to.equal('Test error');
+    expect(error.intuitTid).to.equal('');
+  });
+
+  it('should create a token error with all parameters', () => {
+    const error = new TokenError('Test error', 'TEST_CODE', 'Test description', '1234-5678');
+    expect(error.name).to.equal('TokenError');
+    expect(error.message).to.equal('Test error');
+    expect(error.code).to.equal('TEST_CODE');
+    expect(error.description).to.equal('Test description');
+    expect(error.intuitTid).to.equal('1234-5678');
+  });
+
+  it('should be instanceof Error and OAuthError', () => {
+    const error = new TokenError('Test error');
+    expect(error).to.be.instanceof(Error);
+    expect(error).to.be.instanceof(TokenError);
+  });
+});
+
+describe('Test ValidationError', () => {
+  const ValidationError = require('../src/errors/ValidationError');
+
+  it('should create a validation error with minimal parameters', () => {
+    const error = new ValidationError('Test error');
+    expect(error.name).to.equal('ValidationError');
+    expect(error.message).to.equal('Test error');
+    expect(error.code).to.equal('VALIDATION_ERROR');
+    expect(error.description).to.equal('Test error');
+    expect(error.intuitTid).to.equal('');
+  });
+
+  it('should create a validation error with all parameters', () => {
+    const error = new ValidationError('Test error', 'TEST_CODE', 'Test description', '1234-5678');
+    expect(error.name).to.equal('ValidationError');
+    expect(error.message).to.equal('Test error');
+    expect(error.code).to.equal('TEST_CODE');
+    expect(error.description).to.equal('Test description');
+    expect(error.intuitTid).to.equal('1234-5678');
+  });
+
+  it('should be instanceof Error and OAuthError', () => {
+    const error = new ValidationError('Test error');
+    expect(error).to.be.instanceof(Error);
+    expect(error).to.be.instanceof(ValidationError);
+  });
+});
+
+describe('Test OAuthClient Error Handling', () => {
+  beforeEach(function() {
+    this.timeout(5000);
+    nock.cleanAll();
+    nock.enableNetConnect();
+    nock.disableNetConnect();
+    nock.enableNetConnect('127.0.0.1');
+
+    // Reset the token before each test
+    oauthClient.setToken({
+      access_token: 'sample_access_token',
+      refresh_token: 'sample_refresh_token',
+      token_type: 'bearer',
+      expires_in: 3600,
+      x_refresh_token_expires_in: 8726400,
+      id_token: 'sample_id_token',
+    });
+  });
+
+  afterEach(() => {
+    nock.cleanAll();
+    nock.enableNetConnect();
+  });
+
+  it('should handle API call errors', async function() {
+    const errorResponse = {
+      error: 'Internal Server Error',
+      error_description: 'Something went wrong',
+    };
+
+    const scope = nock('https://sandbox-quickbooks.api.intuit.com')
+      .get('/v3/company/12345/companyinfo/12345')
+      .reply(500, errorResponse, {
+        'Content-Type': 'application/json',
+      });
+
+    try {
+      await oauthClient.makeApiCall({
+        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345',
+        method: 'GET',
+      });
+      expect.fail('Should have thrown an error');
+    } catch (error) {
+      expect(error).to.be.instanceof(OAuthError);
+      expect(error.code).to.equal('INTERNAL_SERVER_ERROR');
+      expect(error.message).to.equal('Internal Server Error');
+      expect(error.description).to.equal('Something went wrong');
+    }
+    scope.done();
+  });
+
+  it('should handle network errors', async function() {
+    const scope = nock('https://sandbox-quickbooks.api.intuit.com')
+      .get('/v3/company/12345/companyinfo/12345')
+      .replyWithError({ code: 'ECONNRESET', message: 'Connection reset by peer' });
+
+    try {
+      await oauthClient.makeApiCall({
+        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345',
+        method: 'GET',
+      });
+      expect.fail('Should have thrown an error');
+    } catch (error) {
+      expect(error).to.be.instanceof(OAuthError);
+      expect(error.code).to.equal('NETWORK_ERROR');
+      expect(error.message).to.equal('Connection reset by peer');
+      expect(error.description).to.equal('A network error occurred while making the request');
+    }
+    scope.done();
+  });
+
+  it('should handle timeout errors', async function() {
+    const scope = nock('https://sandbox-quickbooks.api.intuit.com')
+      .get('/v3/company/12345/companyinfo/12345')
+      .delayConnection(1000)
+      .reply(200);
+
+    try {
+      await oauthClient.makeApiCall({
+        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345',
+        method: 'GET',
+        timeout: 500,
+      });
+      expect.fail('Should have thrown an error');
+    } catch (error) {
+      expect(error).to.be.instanceof(OAuthError);
+      expect(error.code).to.equal('TIMEOUT_ERROR');
+      expect(error.message).to.equal('Request timeout of 500ms exceeded');
+      expect(error.description).to.equal('The request took too long to complete');
+    }
+    scope.done();
+  });
+
+  it('should handle validation errors', async function() {
+    try {
+      await oauthClient.makeApiCall({
+        method: 'GET',
+      });
+      expect.fail('Should have thrown an error');
+    } catch (error) {
+      expect(error).to.be.instanceof(ValidationError);
+      expect(error.message).to.equal('URL is required for API call');
+    }
+  });
+
+  it('should handle rate limit errors', async function() {
+    const scope = nock('https://sandbox-quickbooks.api.intuit.com')
+      .get('/v3/company/12345/companyinfo/12345')
+      .reply(429, {
+        error: 'Rate limit exceeded',
+        error_description: 'Too many requests',
+      }, {
+        'Content-Type': 'application/json',
+      });
+
+    try {
+      await oauthClient.makeApiCall({
+        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/companyinfo/12345',
+        method: 'GET',
+      });
+      expect.fail('Should have thrown an error');
+    } catch (error) {
+      expect(error).to.be.instanceof(OAuthError);
+      expect(error.code).to.equal('RATE_LIMIT_EXCEEDED');
+      expect(error.message).to.equal('Rate limit exceeded');
+      expect(error.description).to.equal('Too many requests, please try again later');
+    }
+    scope.done();
+  });
+});
+
+describe('Test 400 Error Handling with Fault Object', () => {
+  beforeEach(() => {
+    nock.cleanAll();
+    nock.enableNetConnect();
+    nock.disableNetConnect();
+    nock.enableNetConnect('127.0.0.1');
+  });
+
+  afterEach(() => {
+    nock.cleanAll();
+    nock.enableNetConnect();
+  });
+
+  it('should handle 400 response with Fault object correctly', async () => {
+    const faultResponse = {
+      Fault: {
+        Error: [
+          {
+            Message: "Unsupported Operation",
+            Detail: "Operation No resource method found for POST, return 405 with Allow header is not supported.",
+            code: "500"
+          }
+        ],
+        type: "ValidationFault"
+      },
+      time: "2025-05-28T23:25:54.056-07:00"
+    };
+
+    const scope = nock('https://sandbox-quickbooks.api.intuit.com')
+      .post('/v3/company/12345/customer')
+      .reply(400, faultResponse, {
+        'content-type': 'application/json',
+        'intuit_tid': '1234-1234-1234-123'
+      });
+
+    try {
+      await oauthClient.makeApiCall({
+        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/customer',
+        method: 'POST',
+        body: { /* test data */ }
+      });
+      expect.fail('Should have thrown an error');
+    } catch (error) {
+      expect(error).to.be.instanceof(OAuthError);
+      expect(error.message).to.equal('Unsupported Operation');
+      expect(error.code).to.equal('500');
+      expect(error.description).to.equal('Operation No resource method found for POST, return 405 with Allow header is not supported.');
+      expect(error.fault).to.deep.include({
+        type: 'ValidationFault',
+        time: '2025-05-28T23:25:54.056-07:00'
+      });
+      expect(error.fault.errors).to.deep.equal([
+        {
+          message: 'Unsupported Operation',
+          detail: 'Operation No resource method found for POST, return 405 with Allow header is not supported.',
+          code: '500'
+        }
+      ]);
+    }
+
+    scope.done();
+  });
+});
+
+describe('Ensure 400 does not throw AxiosError', () => {
+  beforeEach(() => {
+    nock.cleanAll();
+    nock.enableNetConnect();
+    nock.disableNetConnect();
+    nock.enableNetConnect('127.0.0.1');
+  });
+
+  afterEach(() => {
+    nock.cleanAll();
+    nock.enableNetConnect();
+  });
+
+  it('should not throw AxiosError for 400 response', async () => {
+    const faultResponse = {
+      Fault: {
+        Error: [
+          {
+            Message: 'Test 400 error',
+            Detail: 'This is a test 400 error',
+            code: '400',
+          },
+        ],
+        type: 'ValidationFault',
+      },
+      time: '2025-05-28T23:25:54.056-07:00',
+    };
+
+    nock('https://sandbox-quickbooks.api.intuit.com')
+      .post('/v3/company/12345/customer')
+      .reply(400, faultResponse, {
+        'content-type': 'application/json',
+        'intuit_tid': 'test-tid-400',
+      });
+
+    try {
+      await oauthClient.makeApiCall({
+        url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/12345/customer',
+        method: 'POST',
+        body: { /* test data */ },
+      });
+      expect.fail('Should have thrown an error');
+    } catch (error) {
+      // Should NOT be an AxiosError
+      expect(error.isAxiosError).to.not.be.true;
+      expect(error.name).to.not.equal('AxiosError');
+      // Should be an OAuthError
+      expect(error).to.be.instanceof(OAuthError);
+      expect(error.message).to.equal('Test 400 error');
+      expect(error.code).to.equal('400');
+      expect(error.fault.type).to.equal('ValidationFault');
+    }
+  });
+});
diff --git a/test/mocks/bearer-token.json b/test/mocks/bearer-token.json
index 176a386..9d2b46d 100644
--- a/test/mocks/bearer-token.json
+++ b/test/mocks/bearer-token.json
@@ -2,6 +2,7 @@
   "access_token": "sample_access_token",
   "refresh_token": "sample_refresh_token",
   "token_type": "bearer",
-  "expires_in": "3600",
-  "x_refresh_token_expires_in": "8726400"
+  "expires_in": 3600,
+  "x_refresh_token_expires_in": 8726400,
+  "id_token": "sample_id_token"
 }
diff --git a/test/mocks/jwkResponse.json b/test/mocks/jwkResponse.json
index b01451f..a2de2bd 100644
--- a/test/mocks/jwkResponse.json
+++ b/test/mocks/jwkResponse.json
@@ -1,3 +1,12 @@
 {
-  "body":"{\"keys\": [{\"kty\":\"sample_value_kty\",\"e\":\"sample_value_e\",\"use\":\"sample_value_use\",\"kid\":\"r4p5SbL2qaFehFzhj8gI\",\"alg\":\"sample_value_alg\",\"n\":\"sample_value_n\"}]}"
+  "keys": [
+    {
+      "kty": "RSA",
+      "e": "AQAB",
+      "use": "sig",
+      "kid": "test_kid",
+      "alg": "RS256",
+      "n": "test_n"
+    }
+  ]
 }
diff --git a/test/mocks/makeAPICallResponse.json b/test/mocks/makeAPICallResponse.json
index f1b4f36..0ea03bc 100644
--- a/test/mocks/makeAPICallResponse.json
+++ b/test/mocks/makeAPICallResponse.json
@@ -1,86 +1,10 @@
 {
-  "CompanyInfo":{
-    "CompanyName":"Sample Test",
-    "LegalName":"Sample Test",
-    "CompanyAddr":{
-      "Id":"1",
-      "Line1":"2565 Garcia Avenue",
-      "City":"Mountain View",
-      "Country":"US",
-      "CountrySubDivisionCode":"CA",
-      "PostalCode":"94063"
-    },
-    "CustomerCommunicationAddr":{
-      "Id":"1",
-      "Line1":"2565 Garcia Avenue",
-      "City":"Mountain View",
-      "Country":"US",
-      "CountrySubDivisionCode":"CA",
-      "PostalCode":"94063"
-    },
-    "LegalAddr":{
-      "Id":"1",
-      "Line1":"2565 Garcia Avenue",
-      "City":"Mountain View",
-      "Country":"US",
-      "CountrySubDivisionCode":"CA",
-      "PostalCode":"94063"
-    },
-    "PrimaryPhone":{
-
-    },
-    "CompanyStartDate":"2018-03-03",
-    "FiscalYearStartMonth":"January",
-    "Country":"US",
-    "Email":{
-      "Address":"developer.intuit.com@gmail.com"
-    },
-    "WebAddr":{
-
-    },
-    "SupportedLanguages":"en",
-    "NameValue":[
-      {
-        "Name":"NeoEnabled",
-        "Value":"true"
-      },
-      {
-        "Name":"IsQbdtMigrated",
-        "Value":"false"
-      },
-      {
-        "Name":"SubscriptionStatus",
-        "Value":"TRIAL"
-      },
-      {
-        "Name":"OfferingSku",
-        "Value":"QuickBooks Online Plus"
-      },
-      {
-        "Name":"PayrollFeature",
-        "Value":"true"
-      },
-      {
-        "Name":"AccountantFeature",
-        "Value":"false"
-      },
-      {
-        "Name":"ItemCategoriesFeature",
-        "Value":"true"
-      },
-      {
-        "Name":"AssignedTime",
-        "Value":"2018-03-05T19:38:07-08:00"
-      }
-    ],
-    "domain":"QBO",
-    "sparse":false,
-    "Id":"1",
-    "SyncToken":"21",
-    "MetaData":{
-      "CreateTime":"2018-03-03T01:05:25-08:00",
-      "LastUpdatedTime":"2018-08-23T10:46:22-07:00"
-    }
-  },
-  "time":"2018-09-04T16:53:59.490-07:00"
+  "status": "success",
+  "data": {
+    "id": "12345",
+    "name": "Test Company",
+    "type": "Test Type",
+    "created": "2023-01-01T00:00:00Z",
+    "updated": "2023-01-01T00:00:00Z"
+  }
 }
\ No newline at end of file
diff --git a/test/mocks/refreshResponse.json b/test/mocks/refreshResponse.json
index 4a9788c..02c627c 100644
--- a/test/mocks/refreshResponse.json
+++ b/test/mocks/refreshResponse.json
@@ -1 +1,8 @@
-"{\"access_token\":\"sample_access_token_2\",\"token_type\":\"bearer\",\"x_refresh_token_expires_in\":\"8726400\",\"refresh_token\":\"sample_refresh_token\",\"expires_in\":\"3600\",\"id_token\":\"sample_id_token\"}"
\ No newline at end of file
+{
+  "access_token": "sample_access_token",
+  "refresh_token": "sample_refresh_token",
+  "token_type": "bearer",
+  "expires_in": 3600,
+  "x_refresh_token_expires_in": 8726400,
+  "id_token": "sample_id_token"
+}
\ No newline at end of file
diff --git a/test/mocks/tokenResponse.json b/test/mocks/tokenResponse.json
index 763b48c..9d2b46d 100644
--- a/test/mocks/tokenResponse.json
+++ b/test/mocks/tokenResponse.json
@@ -1,2 +1,8 @@
-
-"{\"access_token\":\"sample_access_token\",\"token_type\":\"bearer\",\"x_refresh_token_expires_in\":\"8726400\",\"refresh_token\":\"sample_refresh_token\",\"expires_in\":\"3600\",\"id_token\":\"sample_id_token\"}"
+{
+  "access_token": "sample_access_token",
+  "refresh_token": "sample_refresh_token",
+  "token_type": "bearer",
+  "expires_in": 3600,
+  "x_refresh_token_expires_in": 8726400,
+  "id_token": "sample_id_token"
+}
diff --git a/test/mocks/userInfo.json b/test/mocks/userInfo.json
index 08c90c8..b40f929 100644
--- a/test/mocks/userInfo.json
+++ b/test/mocks/userInfo.json
@@ -1,7 +1,16 @@
 {
-  "sub": "1182d6ec-2a1f-4aa3-af3f-bb3b95db45af",
-  "email": "john@doe.com",
+  "sub": "test_sub",
+  "email": "test@example.com",
   "emailVerified": true,
-  "givenName": "John",
-  "familyName": "Doe"
+  "givenName": "Test",
+  "familyName": "User",
+  "phoneNumber": "+1234567890",
+  "phoneNumberVerified": true,
+  "address": {
+    "streetAddress": "123 Test St",
+    "locality": "Test City",
+    "region": "Test Region",
+    "postalCode": "12345",
+    "country": "Test Country"
+  }
 }
\ No newline at end of file