Skip to content

Commit a08fccb

Browse files
committed
Add enhanced error logging for API debugging
- Added detailed logging for API URLs being called - Added try-catch around fetch calls with specific error messages - Log full error stack traces in debug mode - Log API response status codes - Better error messages showing the URL that failed - Helps diagnose network and API connectivity issues
1 parent 11e9b13 commit a08fccb

2 files changed

Lines changed: 76 additions & 32 deletions

File tree

dist/index.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25749,20 +25749,31 @@ async function validateFile(filePath, options) {
2574925749
const content = fs.readFileSync(filePath, 'utf8');
2575025750
const validateUrl = buildUrl(baseUrl, '/api/v1/change-set/change-set/validate_yaml/', environment);
2575125751

25752+
core.debug(`Validate URL: ${validateUrl}`);
25753+
2575225754
// Prepare request payload with changeset and variables
2575325755
const requestPayload = {
2575425756
changeset: content,
2575525757
...(changesetVariables && { variables: changesetVariables })
2575625758
};
2575725759

25758-
const validateResponse = await fetch(validateUrl, {
25759-
method: 'POST',
25760-
headers: {
25761-
'Authorization': `Api-Key ${apiKey}`,
25762-
'Content-Type': 'application/json'
25763-
},
25764-
body: JSON.stringify(requestPayload)
25765-
});
25760+
core.debug(`Sending validation request to: ${validateUrl}`);
25761+
let validateResponse;
25762+
try {
25763+
validateResponse = await fetch(validateUrl, {
25764+
method: 'POST',
25765+
headers: {
25766+
'Authorization': `Api-Key ${apiKey}`,
25767+
'Content-Type': 'application/json'
25768+
},
25769+
body: JSON.stringify(requestPayload)
25770+
});
25771+
core.debug(`API response status: ${validateResponse.status}`);
25772+
} catch (error) {
25773+
core.error(`Network error connecting to InProd API: ${error.message}`);
25774+
core.debug(`Full error details: ${error.stack}`);
25775+
throw new Error(`Failed to connect to InProd API at ${validateUrl}: ${error.message}`);
25776+
}
2576625777

2576725778
if (!validateResponse.ok) {
2576825779
const errorBody = await validateResponse.text();
@@ -25823,20 +25834,31 @@ async function executeFile(filePath, options) {
2582325834
const content = fs.readFileSync(filePath, 'utf8');
2582425835
const executeUrl = buildUrl(baseUrl, '/api/v1/change-set/change-set/execute_yaml/', environment);
2582525836

25837+
core.debug(`Execute URL: ${executeUrl}`);
25838+
2582625839
// Prepare request payload with changeset and variables
2582725840
const requestPayload = {
2582825841
changeset: content,
2582925842
...(changesetVariables && { variables: changesetVariables })
2583025843
};
2583125844

25832-
const executeResponse = await fetch(executeUrl, {
25833-
method: 'POST',
25834-
headers: {
25835-
'Authorization': `Api-Key ${apiKey}`,
25836-
'Content-Type': 'application/json'
25837-
},
25838-
body: JSON.stringify(requestPayload)
25839-
});
25845+
core.debug(`Sending API request to: ${executeUrl}`);
25846+
let executeResponse;
25847+
try {
25848+
executeResponse = await fetch(executeUrl, {
25849+
method: 'POST',
25850+
headers: {
25851+
'Authorization': `Api-Key ${apiKey}`,
25852+
'Content-Type': 'application/json'
25853+
},
25854+
body: JSON.stringify(requestPayload)
25855+
});
25856+
core.debug(`API response status: ${executeResponse.status}`);
25857+
} catch (error) {
25858+
core.error(`Network error connecting to InProd API: ${error.message}`);
25859+
core.debug(`Full error details: ${error.stack}`);
25860+
throw new Error(`Failed to connect to InProd API at ${executeUrl}: ${error.message}`);
25861+
}
2584025862

2584125863
if (!executeResponse.ok) {
2584225864
const errorBody = await executeResponse.text();

src/index.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,31 @@ async function validateFile(filePath, options) {
101101
const content = fs.readFileSync(filePath, 'utf8');
102102
const validateUrl = buildUrl(baseUrl, '/api/v1/change-set/change-set/validate_yaml/', environment);
103103

104+
core.debug(`Validate URL: ${validateUrl}`);
105+
104106
// Prepare request payload with changeset and variables
105107
const requestPayload = {
106108
changeset: content,
107109
...(changesetVariables && { variables: changesetVariables })
108110
};
109111

110-
const validateResponse = await fetch(validateUrl, {
111-
method: 'POST',
112-
headers: {
113-
'Authorization': `Api-Key ${apiKey}`,
114-
'Content-Type': 'application/json'
115-
},
116-
body: JSON.stringify(requestPayload)
117-
});
112+
core.debug(`Sending validation request to: ${validateUrl}`);
113+
let validateResponse;
114+
try {
115+
validateResponse = await fetch(validateUrl, {
116+
method: 'POST',
117+
headers: {
118+
'Authorization': `Api-Key ${apiKey}`,
119+
'Content-Type': 'application/json'
120+
},
121+
body: JSON.stringify(requestPayload)
122+
});
123+
core.debug(`API response status: ${validateResponse.status}`);
124+
} catch (error) {
125+
core.error(`Network error connecting to InProd API: ${error.message}`);
126+
core.debug(`Full error details: ${error.stack}`);
127+
throw new Error(`Failed to connect to InProd API at ${validateUrl}: ${error.message}`);
128+
}
118129

119130
if (!validateResponse.ok) {
120131
const errorBody = await validateResponse.text();
@@ -175,20 +186,31 @@ async function executeFile(filePath, options) {
175186
const content = fs.readFileSync(filePath, 'utf8');
176187
const executeUrl = buildUrl(baseUrl, '/api/v1/change-set/change-set/execute_yaml/', environment);
177188

189+
core.debug(`Execute URL: ${executeUrl}`);
190+
178191
// Prepare request payload with changeset and variables
179192
const requestPayload = {
180193
changeset: content,
181194
...(changesetVariables && { variables: changesetVariables })
182195
};
183196

184-
const executeResponse = await fetch(executeUrl, {
185-
method: 'POST',
186-
headers: {
187-
'Authorization': `Api-Key ${apiKey}`,
188-
'Content-Type': 'application/json'
189-
},
190-
body: JSON.stringify(requestPayload)
191-
});
197+
core.debug(`Sending API request to: ${executeUrl}`);
198+
let executeResponse;
199+
try {
200+
executeResponse = await fetch(executeUrl, {
201+
method: 'POST',
202+
headers: {
203+
'Authorization': `Api-Key ${apiKey}`,
204+
'Content-Type': 'application/json'
205+
},
206+
body: JSON.stringify(requestPayload)
207+
});
208+
core.debug(`API response status: ${executeResponse.status}`);
209+
} catch (error) {
210+
core.error(`Network error connecting to InProd API: ${error.message}`);
211+
core.debug(`Full error details: ${error.stack}`);
212+
throw new Error(`Failed to connect to InProd API at ${executeUrl}: ${error.message}`);
213+
}
192214

193215
if (!executeResponse.ok) {
194216
const errorBody = await executeResponse.text();

0 commit comments

Comments
 (0)