Skip to content

Commit

Permalink
fix(reject): fix reject and exit with code 1 if error (#295)
Browse files Browse the repository at this point in the history
* fix(reject): fix reject and exit with code 1 if error
  • Loading branch information
EvgenBabenko authored Sep 23, 2021
1 parent 4b24048 commit 2d090e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
26 changes: 9 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,20 @@ program
)
.option(
"-r, --responses",
"generate additional information about request responses\n" +
"also add typings for bad responses",
"generate additional information about request responses\n" + "also add typings for bad responses",
false,
)
.option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
.option("--route-types", "generate type definitions for API routes", false)
.option("--no-client", "do not generate an API class", false)
.option(
"--enum-names-as-values",
"use values in 'x-enumNames' as enum values (not only as keys)",
false,
)
.option("--enum-names-as-values", "use values in 'x-enumNames' as enum values (not only as keys)", false)
.option(
"--extract-request-params",
"extract request params to data contract (Also combine path params and query params into one object)",
false,
)
.option("--extract-request-body", "extract request body type to data contract", false)
.option(
"--modular",
"generate separated files for http client, data contracts, and routes",
false,
)
.option("--modular", "generate separated files for http client, data contracts, and routes", false)
.option("--js", "generate js api module with declaration file", false)
.option(
"--module-name-index <number>",
Expand All @@ -72,11 +63,7 @@ program
.option("--default-response <type>", "default type for empty response schema", TS_KEYWORDS.VOID)
.option("--type-prefix <string>", "data contract name prefix", "")
.option("--type-suffix <string>", "data contract name suffix", "")
.option(
"--clean-output",
"clean output folder before generate api. WARNING: May cause data loss",
false,
)
.option("--clean-output", "clean output folder before generate api. WARNING: May cause data loss", false)
.option("--patch", "fix up small errors in the swagger source definition", false);

program.parse(process.argv);
Expand Down Expand Up @@ -140,4 +127,9 @@ generateApi({
typePrefix,
typeSuffix,
patch: !!patch,
}).catch((err) => {
// NOTE collect all errors on top level and shows to users in any case
console.error(err);

process.exit(1);
});
10 changes: 8 additions & 2 deletions src/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const parseSwaggerFile = (file) => {
};

const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL, disableProxy) =>
new Promise((resolve) => {
new Promise((resolve, reject) => {
if (pathIsExist(pathToSwagger)) {
logger.log(`try to get swagger by path "${pathToSwagger}"`);
resolve(getFileContent(pathToSwagger));
Expand All @@ -38,7 +38,13 @@ const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL, disablePr
axios
.get(urlToSwagger, axiosOptions)
.then((res) => resolve(res.data))
.catch((err) => logger.error(`error while getting swagger by URL ${urlToSwagger}:`, err));
.catch(() => {
const message = `error while getting swagger by URL ${urlToSwagger}`;

logger.error(message);

reject(message);
});
}
});

Expand Down

0 comments on commit 2d090e7

Please sign in to comment.