Skip to content

Commit

Permalink
Ensure we use request.getErrorMessage() everywhere applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
confused-Techie committed Dec 31, 2024
1 parent a5d94d4 commit 5e7dbf0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Run ppm -v after installing Git to see what version has been detected.\
retries: 4
};
const response = await request.get(requestSettings).catch(error => {
let message = `Request for package information failed: ${error.message}`;
let message = `Request for package information failed: ${request.getErrorMessage(null, error)}`;
if (error.status) { message += ` (${error.status})`; }
throw message;
});
Expand Down
4 changes: 2 additions & 2 deletions src/star.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ Run \`ppm stars\` to see all your starred packages.\
}
};

const response = await request.post(requestSettings).catch(error => { this.logFailure(); throw error; });
const response = await request.post(requestSettings).catch(error => { this.logFailure(); throw request.getErrorMessage(null, error); });
const body = response.body ?? {};
if ((response.statusCode === 404) && ignoreUnpublishedPackages) {
process.stdout.write('skipped (not published)\n'.yellow);
return Promise.reject();
}
if (response.statusCode !== 200) {
this.logFailure();
const message = request.getErrorMessage(body, error);
const message = request.getErrorMessage(body, null);
throw `Starring package failed: ${message}`;
}

Expand Down
8 changes: 4 additions & 4 deletions src/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ name is specified.\

if (packageVersion) { options.url += `/versions/${packageVersion}`; }

const response = await request.del(options).catch(error => { this.logFailure(); throw error; }); //it's not clear why we are calling logFailure in two layers (here and in the usual try-catch around it)
const response = await request.del(options).catch(error => { this.logFailure(); throw request.getErrorMessage(null, error); }); //it's not clear why we are calling logFailure in two layers (here and in the usual try-catch around it)
const body = response.body ?? {};
if (response.statusCode !== 204) {
this.logFailure();
const message = body.message ?? body.error ?? body;
const message = request.getErrorMessage(body, null);
throw `Unpublishing failed: ${message}`;
}

this.logSuccess();
} catch (error) {
this.logFailure();
throw error;
this.logFailure();
throw error;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ View information about a package/theme.\
url: `${config.getAtomPackagesUrl()}/${packageName}`,
json: true
};

const response = await request.get(requestSettings);
const body = response.body ?? {};
if (response.statusCode !== 200) {
const message = body.message ?? body.error ?? body;
const message = request.getErrorMessage(body, null);
throw `Requesting package failed: ${message}`;
}

Expand Down

0 comments on commit 5e7dbf0

Please sign in to comment.