Skip to content

Commit

Permalink
refactor(index): return error messages (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Sep 21, 2023
1 parent fd6f241 commit df842df
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const { joinSafe, normalizeTrim } = require("upath");

const execFileAsync = promisify(execFile);

const errorMessages = {
unk: "Unknown error",
};

/**
* @author Frazer Smith
* @description Checks each option provided is valid, of the correct type, and can be used by specified
Expand Down Expand Up @@ -208,12 +212,18 @@ class UnRTF {
stdErr += data;
});

child.on("close", () => {
child.on("close", (code) => {
/* istanbul ignore else */
if (stdOut !== "") {
resolve(stdOut.trim());
} else if (stdErr !== "") {
reject(new Error(stdErr.trim()));
} else {
reject(new Error(stdErr ? stdErr.trim() : undefined));
reject(
new Error(
code ? errorMessages[code] : errorMessages.unk
)
);
}
});
});
Expand Down

0 comments on commit df842df

Please sign in to comment.