Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ program
.option("--disableProxy", "disabled proxy", false)
.option("--axios", "generate axios http client", false)
.option("--unwrap-response-data", "unwrap the data item from the response", false)
.option("--disable-throw-on-error", "Do not throw an error when response.ok is not true", false)
.option("--single-http-client", "Ability to send HttpClient instance to Api constructor", false)
.option("--silent", "Output only errors to console", false)
.option("--default-response <type>", "default type for empty response schema", TS_KEYWORDS.VOID)
Expand Down Expand Up @@ -90,6 +91,7 @@ const {
cleanOutput,
defaultResponse,
unwrapResponseData,
disableThrowOnError,
sortTypes,
singleHttpClient,
axios,
Expand All @@ -108,6 +110,7 @@ generateApi({
defaultResponseAsSuccess: defaultAsSuccess,
defaultResponseType: defaultResponse,
unwrapResponseData: unwrapResponseData,
disableThrowOnError: disableThrowOnError,
sortTypes: sortTypes,
generateUnionEnums: unionEnums,
generateResponses: responses,
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const config = {
singleHttpClient: false,
httpClientType: HTTP_CLIENT.FETCH,
unwrapResponseData: false,
disableThrowOnError: false,
sortTypes: false,
templatePaths: {
/** `templates/base` */
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
extractRequestBody = config.extractRequestBody,
defaultResponseType = config.defaultResponseType,
unwrapResponseData = config.unwrapResponseData,
disableThrowOnError = config.disableThrowOnError,
sortTypes = config.sortTypes,
singleHttpClient = config.singleHttpClient,
prettier: prettierOptions = getPrettierOptions(),
Expand Down Expand Up @@ -82,6 +83,7 @@ module.exports = {
cleanOutput,
defaultResponseType,
unwrapResponseData,
disableThrowOnError,
sortTypes,
singleHttpClient,
constants,
Expand Down
2 changes: 2 additions & 0 deletions templates/base/http-clients/fetch-http-client.eta
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export class HttpClient<SecurityDataType = unknown> {
this.abortControllers.delete(cancelToken);
}

<% if (!config.disableThrowOnError) { %>
if (!response.ok) throw data;
<% } %>
<% if (config.unwrapResponseData) { %>
return data.data;
<% } else { %>
Expand Down