From 1416e84ca5753cb77e88a9860b78add1adc869b9 Mon Sep 17 00:00:00 2001 From: Javier <javier.garcia@meteologica.com> Date: Tue, 28 Sep 2021 19:37:14 +0200 Subject: [PATCH] feat(typescript-fetch): use ReponseError (#10477) --- .../src/main/resources/typescript-fetch/runtime.mustache | 9 ++++++++- .../typescript-fetch/builds/default-v3.0/runtime.ts | 9 ++++++++- .../petstore/typescript-fetch/builds/default/runtime.ts | 9 ++++++++- .../petstore/typescript-fetch/builds/enum/runtime.ts | 9 ++++++++- .../typescript-fetch/builds/es6-target/src/runtime.ts | 9 ++++++++- .../builds/multiple-parameters/runtime.ts | 9 ++++++++- .../builds/prefix-parameter-interfaces/src/runtime.ts | 9 ++++++++- .../builds/sagas-and-records/src/runtime.ts | 9 ++++++++- .../builds/typescript-three-plus/src/runtime.ts | 9 ++++++++- .../typescript-fetch/builds/with-interfaces/runtime.ts | 9 ++++++++- .../builds/with-npm-version/src/runtime.ts | 9 ++++++++- .../builds/without-runtime-checks/src/runtime.ts | 9 ++++++++- 12 files changed, 96 insertions(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache index 3d68d5a2adf..61c758e55ef 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -39,7 +39,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -101,6 +101,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts index ad34f142a13..41792133bd3 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index 14eb8eb3127..e415b8925fd 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts index 1c4540e2207..980a479dfa5 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts index 14eb8eb3127..e415b8925fd 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts index 14eb8eb3127..e415b8925fd 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts index 14eb8eb3127..e415b8925fd 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts index fcb03abe66c..4b4bc541b7f 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts index fcb03abe66c..4b4bc541b7f 100644 --- a/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts index 14eb8eb3127..e415b8925fd 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts index 14eb8eb3127..e415b8925fd 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { diff --git a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts index 14eb8eb3127..e415b8925fd 100644 --- a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts @@ -50,7 +50,7 @@ export class BaseAPI { if (response.status >= 200 && response.status < 300) { return response; } - throw response; + throw new ResponseError(response, 'Response returned an error code'); } private createFetchParams(context: RequestOpts, initOverrides?: RequestInit) { @@ -112,6 +112,13 @@ export class BaseAPI { } }; +export class ResponseError extends Error { + name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + export class RequiredError extends Error { name: "RequiredError" = "RequiredError"; constructor(public field: string, msg?: string) { -- GitLab