diff --git a/src/formatter/htmlbeautifier.ts b/src/formatter/htmlbeautifier.ts
index 9746eac..b0d93ff 100644
--- a/src/formatter/htmlbeautifier.ts
+++ b/src/formatter/htmlbeautifier.ts
@@ -75,7 +75,13 @@ export default class HtmlBeautifier {
const formattedResult = Buffer.concat(stdoutChunks).toString();
const finalResult = this.handleFinalNewline(input, formattedResult);
const errorMessage = Buffer.concat(stderrChunks).toString();
- this.handleExit(code, finalResult, errorMessage, resolve, reject);
+ if (code && code !== 0) {
+ const error = `Failed with exit code ${code}. ${errorMessage}`;
+ this.handleError(error);
+ reject(error);
+ } else {
+ resolve(finalResult);
+ }
});
htmlbeautifier.stdin.write(input);
@@ -83,30 +89,6 @@ export default class HtmlBeautifier {
});
}
- /**
- * Handles the process exit event and resolves or rejects the promise.
- * @param code The process exit code.
- * @param result The formatted result.
- * @param errorMessage The error message, if any.
- * @param resolve The promise resolve function.
- * @param reject The promise reject function.
- */
- private handleExit(
- code: number | null,
- result: string,
- errorMessage: string,
- resolve: (value: string | PromiseLike) => void,
- reject: (reason?: any) => void
- ): void {
- if (code && code !== 0) {
- const error = `Failed with exit code ${code}. ${errorMessage}`;
- this.handleError(error);
- reject(error);
- } else {
- resolve(result);
- }
- }
-
/**
* Handles errors by logging and displaying a message to the user.
* @param error The error object or message.