Skip to content

Commit

Permalink
handle error if no readme is present
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Aug 19, 2018
1 parent 356f225 commit 7069105
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/artifactory-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ function name2url({ scope, packageName }) {

function readme2Html(dir) {
const readmeFile = `${dir}/package/README.md`; // TODO: ignore case
const readme = fs.readFileSync(readmeFile);
let readme;
try {
readme = fs.readFileSync(readmeFile);
} catch(error) {
readme = "No README.md file present.";
}
const converter = new showdown.Converter();
const html = converter.makeHtml(readme.toString());
return html;
Expand Down Expand Up @@ -59,7 +64,7 @@ async function getPackageDetail({ scope, packageName }) {
const latestVersion = latestVersionResponse.data.latest;
const downloadUrl = packageDetail.versions[latestVersion].dist.tarball;
const storageDir = `${tmpDir}/${scope}/${packageName}/${latestVersion}`;
if (fs.existsSync(`${storageDir}/package/README.md`)) {
if (fs.existsSync(storageDir)) {
resolve(readme2Html(storageDir));
} else {
axios
Expand Down

0 comments on commit 7069105

Please sign in to comment.