Skip to content

Commit e2ff631

Browse files
committed
added Exception analysis console log to capture Fault errors
1 parent 372646a commit e2ff631

File tree

7 files changed

+468
-130
lines changed

7 files changed

+468
-130
lines changed

.eslintrc.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@
77
"strict": ["error", "safe"],
88
"prefer-object-spread": "off",
99
"no-param-reassign": "off",
10-
"comma-dangle": [
11-
"error",
12-
{
13-
"arrays": "always-multiline",
14-
"objects": "always-multiline",
15-
"imports": "always-multiline",
16-
"exports": "always-multiline",
17-
"functions": "never"
18-
}
19-
],
10+
"comma-dangle": ["error", "always-multiline"],
2011
"no-underscore-dangle": "off",
2112
"no-unused-expressions": "off"
2213
},

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "intuit-oauth",
3-
"version": "4.2.0",
3+
"version": "4.2.1",
44
"description": "Intuit Node.js client for OAuth2.0 and OpenIDConnect",
55
"main": "./src/OAuthClient.js",
66
"scripts": {
@@ -68,14 +68,15 @@
6868
"homepage": "https://github.com/intuit/oauth-jsclient",
6969
"dependencies": {
7070
"atob": "2.1.2",
71-
"axios": "^1.5.1",
71+
"axios": "^1.9.0",
7272
"csrf": "^3.0.4",
7373
"jsonwebtoken": "^9.0.2",
7474
"query-string": "^6.12.1",
7575
"rsa-pem-from-mod-exp": "^0.8.4",
7676
"winston": "^3.1.0"
7777
},
7878
"devDependencies": {
79+
"@snyk/protect": "^1.657.0",
7980
"btoa": "^1.2.1",
8081
"chai": "^4.1.2",
8182
"chai-as-promised": "^7.1.1",
@@ -87,8 +88,7 @@
8788
"nock": "^9.2.3",
8889
"nyc": "^15.0.1",
8990
"prettier": "^2.0.5",
90-
"sinon": "^9.0.2",
91-
"@snyk/protect": "^1.657.0"
91+
"sinon": "^9.0.2"
9292
},
9393
"snyk": true
9494
}

sample/app.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,65 @@ app.get('/getCompanyInfo', function (req, res) {
124124
res.send(resp);
125125
})
126126
.catch(function (e) {
127-
console.error(e);
127+
// Detailed error analysis
128+
const errorAnalysis = {
129+
// Basic error properties
130+
basic: {
131+
name: e.name,
132+
message: e.message,
133+
stack: e.stack,
134+
code: e.code
135+
},
136+
// Response analysis
137+
response: e.response ? {
138+
status: e.response.status,
139+
statusText: e.response.statusText,
140+
headers: JSON.stringify(e.response.headers),
141+
// Deep analysis of response data
142+
data: JSON.stringify(e.response.data),
143+
// Specific Fault object analysis
144+
fault: JSON.stringify(e.response.data && e.response.data.Fault ? {
145+
type: e.response.data.Fault.type,
146+
error: e.response.data.Fault.Error ? e.response.data.Fault.Error.map(err => ({
147+
message: err.Message,
148+
detail: err.Detail,
149+
code: err.code,
150+
element: err.element,
151+
additionalInfo: err.additionalInfo
152+
})) : null,
153+
timestamp: e.response.data.time
154+
} : null),
155+
// OAuth error fields
156+
oauth: {
157+
error:e.response.data && e.response.data.error,
158+
error_description: e.response.data && e.response.data.error_description
159+
}
160+
} : null,
161+
// Request analysis
162+
request: e.request ? {
163+
method: e.request.method,
164+
path: e.request.path,
165+
headers: e.request.headers
166+
} : null
167+
};
168+
169+
// Log the detailed error analysis
170+
console.error('Exception Analysis:', {
171+
hasFaultObject: !!(e.response && e.response.data && e.response.data.Fault),
172+
faultType: e.response && e.response.data && e.response.data.Fault && e.response.data.Fault.type,
173+
faultErrors: e.response && e.response.data && e.response.data.Fault && e.response.data.Fault.Error,
174+
fullAnalysis: errorAnalysis
175+
});
176+
177+
// Send error response to client
178+
res.status(e.response ? e.response.status : 500).json({
179+
error: true,
180+
message: e.message,
181+
fault: e.response && e.response.data && e.response.data.Fault ? {
182+
type: e.response.data.Fault.type,
183+
errors: e.response.data.Fault.Error
184+
} : null
185+
});
128186
});
129187
});
130188

0 commit comments

Comments
 (0)