Skip to content

Commit 0fa1e52

Browse files
committed
Clean up
1 parent 8b8c013 commit 0fa1e52

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/cmd/esim.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = class eSimCommands extends CLICommandBase {
5454

5555
const profiles = eidBlock?.profiles;
5656

57-
console.log(`${os.EOL}Provisioning the following profiles: `);
57+
console.log(`${os.EOL}Provisioning the following profiles to EID ${eid}:`);
5858
profiles.forEach((profile, index) => {
5959
const rspUrl = `1\$${profile.smdp}\$${profile.matching_id}`;
6060
console.log(`\t${index + 1}. ${profile.provider} (${rspUrl})`);
@@ -66,11 +66,12 @@ module.exports = class eSimCommands extends CLICommandBase {
6666
console.log(`${os.EOL}${index + 1}. Downloading ${profile.provider} profile from ${rspUrl}`);
6767

6868
const start = Date.now();
69+
let timeTaken = 0;
6970
let iccid = null;
7071

7172
try {
7273
const res = await execa(this.lpa, ['download', rspUrl, `--serial=${port}`]);
73-
const timeTaken = ((Date.now() - start) / 1000).toFixed(2);
74+
timeTaken = ((Date.now() - start) / 1000).toFixed(2);
7475

7576
const output = res.stdout;
7677
if (output.includes('Profile successfully downloaded')) {
@@ -93,8 +94,17 @@ module.exports = class eSimCommands extends CLICommandBase {
9394

9495
this._addToJson(this.outputJson, outputData);
9596
} catch (err) {
96-
console.error(`${os.EOL}\tFailed to download profile: ${err.message}`);
97+
const outputData = {
98+
EID: eid,
99+
provider: profile.provider,
100+
iccid,
101+
time: timeTaken,
102+
output: err.message,
103+
};
104+
this._addToJson(this.outputJson, outputData);
105+
throw new Error('Failed to download profile');
97106
}
107+
98108
}
99109

100110
console.log(`${os.EOL}Provisioning complete`);
@@ -239,7 +249,6 @@ module.exports = class eSimCommands extends CLICommandBase {
239249

240250
// Write updated JSON back to the file with indentation
241251
fs.writeFileSync(jsonFile, JSON.stringify(existingJson, null, 4));
242-
console.log('Data appended successfully');
243252
} catch (error) {
244253
console.error(`Failed to append data to JSON file: ${error.message}`);
245254
}

0 commit comments

Comments
 (0)