From 2b537df2b7683b7bb6b496fc2151267eddaacff2 Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Tue, 17 Sep 2024 20:59:32 +0200 Subject: [PATCH] fix tests --- .../Client/Language/php-operation.php.twig | 35 +++++---- .../Language/typescript-operation.ts.twig | 11 ++- .../Generator/Client/resource/php/Client.php | 67 +++++++++-------- .../Client/resource/php_collection/BarTag.php | 10 +-- .../resource/php_collection/FooBarTag.php | 24 +++---- .../resource/php_collection/FooBazTag.php | 10 +-- .../resource/php_content_type/Client.php | 72 +++++++++---------- .../Client/resource/php_import/Client.php | 11 ++- .../Client/resource/php_test/ProductTag.php | 25 ++----- .../Client/resource/typescript/Client.ts | 55 +++++++------- .../resource/typescript_collection/BarTag.ts | 10 +-- .../typescript_collection/FooBarTag.ts | 20 +++--- .../typescript_collection/FooBazTag.ts | 10 +-- .../typescript_content_type/Client.ts | 54 +++++++------- .../resource/typescript_import/Client.ts | 9 ++- .../resource/typescript_test/ProductTag.ts | 25 ++----- 16 files changed, 184 insertions(+), 264 deletions(-) diff --git a/src/Generator/Client/Language/php-operation.php.twig b/src/Generator/Client/Language/php-operation.php.twig index 66f4a0e..cd3200c 100644 --- a/src/Generator/Client/Language/php-operation.php.twig +++ b/src/Generator/Client/Language/php-operation.php.twig @@ -64,15 +64,14 @@ $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { {% for code, throw in operation.throws %} - case {% if code == 999 %}$statusCode >= 0 && $statusCode <= 999{% elseif code == 499 %}$statusCode >= 400 && $statusCode <= 499{% elseif code == 599 %}$statusCode >= 500 && $statusCode <= 599{% else %}$statusCode === {{ code }}{% endif %}: + if ({% if code == 999 %}$statusCode >= 0 && $statusCode <= 999{% elseif code == 499 %}$statusCode >= 400 && $statusCode <= 499{% elseif code == 599 %}$statusCode >= 500 && $statusCode <= 599{% else %}$statusCode === {{ code }}{% endif %}) { {{ _self.response(operation.return, true) }} - throw new {{ throw.className|raw }}($data); -{% endfor %} - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new {{ throw.className|raw }}($data); } + +{% endfor %} + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -82,27 +81,27 @@ {% macro response(payload, in_throw) %} {% if payload.contentType == 'application/octet-stream' %} - {% if in_throw %} {% endif %}$data = $body; + {% if in_throw %} {% endif %}$data = $body; {% elseif payload.contentType == 'application/x-www-form-urlencoded' %} - {% if in_throw %} {% endif %}$data = []; - {% if in_throw %} {% endif %}parse_str((string) $body, $data); + {% if in_throw %} {% endif %}$data = []; + {% if in_throw %} {% endif %}parse_str((string) $body, $data); {% elseif payload.contentType == 'application/json' %} - {% if in_throw %} {% endif %}$data = \json_decode((string) $body); + {% if in_throw %} {% endif %}$data = \json_decode((string) $body); {% elseif payload.contentType == 'multipart/form-data' %} - {% if in_throw %} {% endif %}// @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed - {% if in_throw %} {% endif %}$data = []; + {% if in_throw %} {% endif %}// @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed + {% if in_throw %} {% endif %}$data = []; {% elseif payload.contentType == 'text/plain' %} - {% if in_throw %} {% endif %}$data = (string) $body; + {% if in_throw %} {% endif %}$data = (string) $body; {% elseif payload.contentType == 'application/xml' %} - {% if in_throw %} {% endif %}$data = new \DOMDocument(); - {% if in_throw %} {% endif %}$data->loadXML((string) $body); + {% if in_throw %} {% endif %}$data = new \DOMDocument(); + {% if in_throw %} {% endif %}$data->loadXML((string) $body); {% else %} {% if payload.innerSchema.isMap %} - {% if in_throw %} {% endif %}$data = $this->parser->parse((string) $body, {{ payload.innerSchema.type }}::class, isMap: true); + {% if in_throw %} {% endif %}$data = $this->parser->parse((string) $body, {{ payload.innerSchema.type }}::class, isMap: true); {% elseif payload.innerSchema.isArray %} - {% if in_throw %} {% endif %}$data = $this->parser->parse((string) $body, {{ payload.innerSchema.type }}::class, isArray: true); + {% if in_throw %} {% endif %}$data = $this->parser->parse((string) $body, {{ payload.innerSchema.type }}::class, isArray: true); {% else %} - {% if in_throw %} {% endif %}$data = $this->parser->parse((string) $body, {{ payload.schema.type }}::class); + {% if in_throw %} {% endif %}$data = $this->parser->parse((string) $body, {{ payload.schema.type }}::class); {% endif %} {% endif %} {% endmacro %} diff --git a/src/Generator/Client/Language/typescript-operation.ts.twig b/src/Generator/Client/Language/typescript-operation.ts.twig index 7fca258..dec798a 100644 --- a/src/Generator/Client/Language/typescript-operation.ts.twig +++ b/src/Generator/Client/Language/typescript-operation.ts.twig @@ -59,14 +59,13 @@ } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { {% for code, throw in operation.throws %} - case {% if code == 999 %}statusCode >= 0 && statusCode <= 999{% elseif code == 499 %}statusCode >= 400 && statusCode <= 499{% elseif code == 599 %}statusCode >= 500 && statusCode <= 599{% else %}statusCode === {{ code }}{% endif %}: - throw new {{ throw.className|raw }}(error.response.data); -{% endfor %} - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if ({% if code == 999 %}statusCode >= 0 && statusCode <= 999{% elseif code == 499 %}statusCode >= 400 && statusCode <= 499{% elseif code == 599 %}statusCode >= 500 && statusCode <= 599{% else %}statusCode === {{ code }}{% endif %}) { + throw new {{ throw.className|raw }}(error.response.data); } + +{% endfor %} + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } diff --git a/tests/Generator/Client/resource/php/Client.php b/tests/Generator/Client/resource/php/Client.php index 9af06d9..6091040 100644 --- a/tests/Generator/Client/resource/php/Client.php +++ b/tests/Generator/Client/resource/php/Client.php @@ -65,10 +65,7 @@ public function get(string $name, string $type, ?int $startIndex = null, ?float $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -111,18 +108,19 @@ public function create(string $name, string $type, EntryCreate $payload): EntryM $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode === 400: - $data = $this->parser->parse((string) $body, EntryMessage::class); + if ($statusCode === 400) { + $data = $this->parser->parse((string) $body, EntryMessage::class); + + throw new EntryMessageException($data); + } - throw new EntryMessageException($data); - case $statusCode === 500: - $data = $this->parser->parse((string) $body, EntryMessage::class); + if ($statusCode === 500) { + $data = $this->parser->parse((string) $body, EntryMessage::class); - throw new EntryMessageException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new EntryMessageException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -166,18 +164,19 @@ public function update(string $name, string $type, \PSX\Record\Record $payload): $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode === 400: - $data = $this->parser->parse((string) $body, EntryMessage::class, isMap: true); + if ($statusCode === 400) { + $data = $this->parser->parse((string) $body, EntryMessage::class, isMap: true); + + throw new EntryMessageException($data); + } - throw new EntryMessageException($data); - case $statusCode === 500: - $data = $this->parser->parse((string) $body, EntryMessage::class, isMap: true); + if ($statusCode === 500) { + $data = $this->parser->parse((string) $body, EntryMessage::class, isMap: true); - throw new MapEntryMessageException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new MapEntryMessageException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -214,10 +213,7 @@ public function delete(string $name, string $type): void $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -261,18 +257,19 @@ public function patch(string $name, string $type, array $payload): array $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode === 400: - $data = $this->parser->parse((string) $body, EntryMessage::class, isArray: true); + if ($statusCode === 400) { + $data = $this->parser->parse((string) $body, EntryMessage::class, isArray: true); - throw new EntryMessageException($data); - case $statusCode === 500: - $data = $this->parser->parse((string) $body, EntryMessage::class, isArray: true); + throw new EntryMessageException($data); + } - throw new ArrayEntryMessageException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if ($statusCode === 500) { + $data = $this->parser->parse((string) $body, EntryMessage::class, isArray: true); + + throw new ArrayEntryMessageException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } diff --git a/tests/Generator/Client/resource/php_collection/BarTag.php b/tests/Generator/Client/resource/php_collection/BarTag.php index 70698e9..e9f94d2 100644 --- a/tests/Generator/Client/resource/php_collection/BarTag.php +++ b/tests/Generator/Client/resource/php_collection/BarTag.php @@ -48,10 +48,7 @@ public function find(string $foo): EntryCollection $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -89,10 +86,7 @@ public function put(EntryCreate $payload): EntryMessage $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } diff --git a/tests/Generator/Client/resource/php_collection/FooBarTag.php b/tests/Generator/Client/resource/php_collection/FooBarTag.php index 00546e7..55c27a7 100644 --- a/tests/Generator/Client/resource/php_collection/FooBarTag.php +++ b/tests/Generator/Client/resource/php_collection/FooBarTag.php @@ -46,10 +46,7 @@ public function get(): EntryCollection $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -88,18 +85,19 @@ public function create(EntryCreate $payload): EntryMessage $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode === 400: - $data = $this->parser->parse((string) $body, EntryMessage::class); + if ($statusCode === 400) { + $data = $this->parser->parse((string) $body, EntryMessage::class); + + throw new EntryMessageException($data); + } - throw new EntryMessageException($data); - case $statusCode === 500: - $data = $this->parser->parse((string) $body, EntryMessage::class); + if ($statusCode === 500) { + $data = $this->parser->parse((string) $body, EntryMessage::class); - throw new EntryMessageException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new EntryMessageException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } diff --git a/tests/Generator/Client/resource/php_collection/FooBazTag.php b/tests/Generator/Client/resource/php_collection/FooBazTag.php index 8b5602c..3ed6e00 100644 --- a/tests/Generator/Client/resource/php_collection/FooBazTag.php +++ b/tests/Generator/Client/resource/php_collection/FooBazTag.php @@ -48,10 +48,7 @@ public function get(string $year): EntryCollection $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -89,10 +86,7 @@ public function create(EntryCreate $payload): EntryMessage $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } diff --git a/tests/Generator/Client/resource/php_content_type/Client.php b/tests/Generator/Client/resource/php_content_type/Client.php index 07ba056..a0f7c65 100644 --- a/tests/Generator/Client/resource/php_content_type/Client.php +++ b/tests/Generator/Client/resource/php_content_type/Client.php @@ -51,14 +51,13 @@ public function binary(\Psr\Http\Message\StreamInterface $body): \Psr\Http\Messa $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode >= 0 && $statusCode <= 999: - $data = $body; + if ($statusCode >= 0 && $statusCode <= 999) { + $data = $body; - throw new BinaryException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new BinaryException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -99,15 +98,14 @@ public function form(array $body): array $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode >= 500 && $statusCode <= 599: - $data = []; - parse_str((string) $body, $data); + if ($statusCode >= 500 && $statusCode <= 599) { + $data = []; + parse_str((string) $body, $data); - throw new FormException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new FormException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -147,14 +145,13 @@ public function json(\stdClass $body): \stdClass $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode >= 400 && $statusCode <= 499: - $data = \json_decode((string) $body); + if ($statusCode >= 400 && $statusCode <= 499) { + $data = \json_decode((string) $body); - throw new JsonException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new JsonException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -195,15 +192,14 @@ public function multipart(array $body): array $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode === 500: - // @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed - $data = []; + if ($statusCode === 500) { + // @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed + $data = []; - throw new MultipartException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new MultipartException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -243,14 +239,13 @@ public function text(string $body): string $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode === 500: - $data = (string) $body; + if ($statusCode === 500) { + $data = (string) $body; - throw new TextException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new TextException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -291,15 +286,14 @@ public function xml(\DOMDocument $body): \DOMDocument $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode === 500: - $data = new \DOMDocument(); - $data->loadXML((string) $body); + if ($statusCode === 500) { + $data = new \DOMDocument(); + $data->loadXML((string) $body); - throw new XmlException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new XmlException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } diff --git a/tests/Generator/Client/resource/php_import/Client.php b/tests/Generator/Client/resource/php_import/Client.php index 553b7c1..9f89d98 100644 --- a/tests/Generator/Client/resource/php_import/Client.php +++ b/tests/Generator/Client/resource/php_import/Client.php @@ -48,14 +48,13 @@ public function foo(): \External\Bar\MyType $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - case $statusCode === 500: - $data = $this->parser->parse((string) $body, \External\Bar\MyType::class); + if ($statusCode === 500) { + $data = $this->parser->parse((string) $body, \External\Bar\MyType::class); - throw new ImportMyTypeException($data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + throw new ImportMyTypeException($data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } diff --git a/tests/Generator/Client/resource/php_test/ProductTag.php b/tests/Generator/Client/resource/php_test/ProductTag.php index 263dc1e..f197919 100644 --- a/tests/Generator/Client/resource/php_test/ProductTag.php +++ b/tests/Generator/Client/resource/php_test/ProductTag.php @@ -52,10 +52,7 @@ public function getAll(?int $startIndex = null, ?int $count = null, ?string $sea $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -95,10 +92,7 @@ public function create(TestRequest $payload): TestResponse $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -140,10 +134,7 @@ public function update(int $id, TestRequest $payload): TestResponse $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -185,10 +176,7 @@ public function patch(int $id, TestRequest $payload): TestResponse $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } @@ -228,10 +216,7 @@ public function delete(int $id): TestResponse $body = $e->getResponse()->getBody(); $statusCode = $e->getResponse()->getStatusCode(); - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } catch (\Throwable $e) { throw new ClientException('An unknown error occurred: ' . $e->getMessage()); } diff --git a/tests/Generator/Client/resource/typescript/Client.ts b/tests/Generator/Client/resource/typescript/Client.ts index 04582cc..24dd71d 100644 --- a/tests/Generator/Client/resource/typescript/Client.ts +++ b/tests/Generator/Client/resource/typescript/Client.ts @@ -58,10 +58,7 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -99,14 +96,15 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode === 400: - throw new EntryMessageException(error.response.data); - case statusCode === 500: - throw new EntryMessageException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode === 400) { + throw new EntryMessageException(error.response.data); + } + + if (statusCode === 500) { + throw new EntryMessageException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -145,14 +143,15 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode === 400: - throw new EntryMessageException(error.response.data); - case statusCode === 500: - throw new MapEntryMessageException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode === 400) { + throw new EntryMessageException(error.response.data); + } + + if (statusCode === 500) { + throw new MapEntryMessageException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -187,10 +186,7 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -229,14 +225,15 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode === 400: - throw new EntryMessageException(error.response.data); - case statusCode === 500: - throw new ArrayEntryMessageException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode === 400) { + throw new EntryMessageException(error.response.data); } + + if (statusCode === 500) { + throw new ArrayEntryMessageException(error.response.data); + } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } diff --git a/tests/Generator/Client/resource/typescript_collection/BarTag.ts b/tests/Generator/Client/resource/typescript_collection/BarTag.ts index 7ecef7c..d25e5b3 100644 --- a/tests/Generator/Client/resource/typescript_collection/BarTag.ts +++ b/tests/Generator/Client/resource/typescript_collection/BarTag.ts @@ -42,10 +42,7 @@ export class BarTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -80,10 +77,7 @@ export class BarTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } diff --git a/tests/Generator/Client/resource/typescript_collection/FooBarTag.ts b/tests/Generator/Client/resource/typescript_collection/FooBarTag.ts index 7079151..61ec619 100644 --- a/tests/Generator/Client/resource/typescript_collection/FooBarTag.ts +++ b/tests/Generator/Client/resource/typescript_collection/FooBarTag.ts @@ -42,10 +42,7 @@ export class FooBarTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -81,14 +78,15 @@ export class FooBarTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode === 400: - throw new EntryMessageException(error.response.data); - case statusCode === 500: - throw new EntryMessageException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode === 400) { + throw new EntryMessageException(error.response.data); + } + + if (statusCode === 500) { + throw new EntryMessageException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } diff --git a/tests/Generator/Client/resource/typescript_collection/FooBazTag.ts b/tests/Generator/Client/resource/typescript_collection/FooBazTag.ts index 67dd2f7..eff6fd3 100644 --- a/tests/Generator/Client/resource/typescript_collection/FooBazTag.ts +++ b/tests/Generator/Client/resource/typescript_collection/FooBazTag.ts @@ -42,10 +42,7 @@ export class FooBazTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -80,10 +77,7 @@ export class FooBazTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } diff --git a/tests/Generator/Client/resource/typescript_content_type/Client.ts b/tests/Generator/Client/resource/typescript_content_type/Client.ts index ee4cde4..0390cb0 100644 --- a/tests/Generator/Client/resource/typescript_content_type/Client.ts +++ b/tests/Generator/Client/resource/typescript_content_type/Client.ts @@ -47,12 +47,11 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode >= 0 && statusCode <= 999: - throw new BinaryException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode >= 0 && statusCode <= 999) { + throw new BinaryException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -89,12 +88,11 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode >= 500 && statusCode <= 599: - throw new FormException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode >= 500 && statusCode <= 599) { + throw new FormException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -132,12 +130,11 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode >= 400 && statusCode <= 499: - throw new JsonException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode >= 400 && statusCode <= 499) { + throw new JsonException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -174,12 +171,11 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode === 500: - throw new MultipartException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode === 500) { + throw new MultipartException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -217,12 +213,11 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode === 500: - throw new TextException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode === 500) { + throw new TextException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -260,12 +255,11 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode === 500: - throw new XmlException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode === 500) { + throw new XmlException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } diff --git a/tests/Generator/Client/resource/typescript_import/Client.ts b/tests/Generator/Client/resource/typescript_import/Client.ts index 3dbee8f..4581fcf 100644 --- a/tests/Generator/Client/resource/typescript_import/Client.ts +++ b/tests/Generator/Client/resource/typescript_import/Client.ts @@ -40,12 +40,11 @@ export class Client extends ClientAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - case statusCode === 500: - throw new ImportMyTypeException(error.response.data); - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); + if (statusCode === 500) { + throw new ImportMyTypeException(error.response.data); } + + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } diff --git a/tests/Generator/Client/resource/typescript_test/ProductTag.ts b/tests/Generator/Client/resource/typescript_test/ProductTag.ts index eb24fb4..0c02ba0 100644 --- a/tests/Generator/Client/resource/typescript_test/ProductTag.ts +++ b/tests/Generator/Client/resource/typescript_test/ProductTag.ts @@ -43,10 +43,7 @@ export class ProductTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -83,10 +80,7 @@ export class ProductTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -124,10 +118,7 @@ export class ProductTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -165,10 +156,7 @@ export class ProductTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); } @@ -205,10 +193,7 @@ export class ProductTag extends TagAbstract { } else if (axios.isAxiosError(error) && error.response) { const statusCode = error.response.status; - switch (true) { - default: - throw new UnknownStatusCodeException('The server returned an unknown status code'); - } + throw new UnknownStatusCodeException('The server returned an unknown status code'); } else { throw new ClientException('An unknown error occurred: ' + String(error)); }