Skip to content

Commit 1e59337

Browse files
authored
Msp dashboard: Update error handling in software-related actions (#23065)
For: fleetdm/confidential#8473 Changes: - Updated the cloud error components message - Updated the upload-software action to log errors about failed requests to the Fleet API - Updated the edit-software action to log errors about failed requests to the Fleet API, and to delete temporary files when requests fail. - Updated the software page to clear cloud errors when modals are closed.
1 parent 91eef00 commit 1e59337

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

ee/bulk-operations-dashboard/api/controllers/software/edit-software.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,15 @@ module.exports = {
160160
};
161161
},
162162
})
163-
.intercept((error)=>{
163+
.intercept(async (error)=>{
164164
// Note: with this current behavior, all errors from this upload are currently swallowed and a softwareUploadFailed response is returned.
165165
// FUTURE: Test to make sure that uploading duplicate software to a team results in a 409 response.
166+
// Before handline errors, decide what to do about the file uploaded to s3, if this is undeployed software, we'll leave it alone, but if this was a temporary file created to transfer it between teams on the Fleet instance, we'll delete the file.
167+
if(!software.id) {// If the software does not have an ID, it not stored in the app's database/s3 bucket, so we can safely delete the file in s3.
168+
await sails.rm(sails.config.uploads.prefixForFileDeletion+softwareFd);
169+
}
170+
// Log a warning containing an error
171+
sails.log.warn(`When attempting to upload a software installer, an unexpected error occurred communicating with the Fleet API, ${require('util').inspect(error, {depth: 0})}`);
166172
return {'softwareUploadFailed': error};
167173
});
168174
// console.timeEnd(`transfering ${software.name} to fleet instance for team id ${team}`);
@@ -229,9 +235,15 @@ module.exports = {
229235
};
230236
},
231237
})
232-
.intercept((error)=>{
238+
.intercept(async (error)=>{
233239
// Note: with this current behavior, all errors from this upload are currently swallowed and a softwareUploadFailed response is returned.
234240
// FUTURE: Test to make sure that uploading duplicate software to a team results in a 409 response.
241+
// Before handling errors, decide what to do about the file uploaded to s3, if this is undeployed software, we'll leave it alone, but if this was a temporary file created to transfer it between teams on the Fleet instance, we'll delete the file.
242+
if(!software.id) {
243+
await sails.rm(sails.config.uploads.prefixForFileDeletion+softwareFd);
244+
}
245+
// Log a warning containing an error
246+
sails.log.warn(`When attempting to upload a software installer, an unexpected error occurred communicating with the Fleet API, ${require('util').inspect(error, {depth: 0})}`);
235247
return {'softwareUploadFailed': error};
236248
});
237249
// console.timeEnd(`transfering ${software.name} to fleet instance for team id ${teamApid}`);

ee/bulk-operations-dashboard/api/controllers/software/upload-software.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ module.exports = {
3333
statusCode: 409,
3434
},
3535

36+
softwareUploadFailed: {
37+
description:'An unexpected error occurred communicating with the Fleet API'
38+
}
39+
3640
},
3741

3842

@@ -51,8 +55,8 @@ module.exports = {
5155
};
5256
await UndeployedSoftware.create(newSoftwareInfo);
5357
} else {
58+
uploadedSoftware = await sails.uploadOne(newSoftware, {bucket: sails.config.uploads.bucketWithPostfix});
5459
for(let teamApid of teams) {
55-
uploadedSoftware = await sails.uploadOne(newSoftware, {bucket: sails.config.uploads.bucketWithPostfix});
5660
var WritableStream = require('stream').Writable;
5761
await sails.cp(uploadedSoftware.fd, {bucket: sails.config.uploads.bucketWithPostfix}, {
5862
adapter: ()=>{
@@ -96,8 +100,14 @@ module.exports = {
96100
};
97101
}
98102
})
99-
.intercept({response: {status: 409}}, (error)=>{
103+
.intercept({response: {status: 409}}, async (error)=>{
104+
await sails.rm(sails.config.uploads.prefixForFileDeletion+uploadedSoftware.fd);
100105
return {'softwareAlreadyExistsOnThisTeam': error};
106+
})
107+
.intercept({name: 'AxiosError'}, async (error)=>{
108+
await sails.rm(sails.config.uploads.prefixForFileDeletion+uploadedSoftware.fd);
109+
sails.log.warn(`When attempting to upload a software installer, an unexpected error occurred communicating with the Fleet API, ${require('util').inspect(error, {depth: 0})}`);
110+
return {'softwareUploadFailed': error};
101111
});
102112
}
103113
// Remove the file from the s3 bucket after it has been sent to the Fleet server.

ee/bulk-operations-dashboard/assets/js/components/cloud-error.component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ parasails.registerComponent('cloud-error', {
4343
// ╩ ╩ ╩ ╩ ╩╩═╝
4444
template: `
4545
<div>
46-
<p :class="{ 'm-0': beWithoutMargins }" class="text-danger"><slot name="default">An error occured while processing your request. Please check your information and try again, or <a href="/contact">contact support</a> if the error persists.</slot></p>
46+
<p :class="{ 'm-0': beWithoutMargins }" class="text-danger"><slot name="default">An unexpected error occurred communicating with the Fleet API</slot></p>
4747
</div>
4848
`,
4949

ee/bulk-operations-dashboard/assets/js/pages/software/software.page.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ parasails.registerPage('software', {
9595
this.modal = '';
9696
this.formErrors = {};
9797
this.formData = {};
98+
this.cloudError = '';
9899
this.showAdvancedOptions = false;
99100
await this.forceRender();
100101
},

0 commit comments

Comments
 (0)