Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fetch): Improved error handling when body does not exist in fetch client #1870

Merged

Conversation

soartec-lab
Copy link
Member

@soartec-lab soartec-lab commented Feb 1, 2025

Status

READY

Description

fix #1854
The automatically generated source code has been changed as follows.

When includeHttpResponseReturnType is true (default):

+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
- const data: Pet = [204, 205, 304].includes(res.status) || !res.body ? {} : await res.json();
+ const data: showPetByIdResponse['data'] = body ? JSON.parse(body) : {};

-  return { status: res.status, data, headers: res.headers };
+  return { data, status: res.status, headers: res.headers } as showPetByIdResponse;

When includeHttpResponseReturnType is false:

+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
- const data: Pet = [204, 205, 304].includes(res.status) || !res.body ? {} : await res.json();
+ const data: Pets = body ? JSON.parse(body) : {};

-  return data as Pets
+  return data;

Related PRs

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

Both patterns of options you can see in the sample app.

@soartec-lab soartec-lab changed the title fix: Improved error handling when body does not exist in fetch client. fix: Improved error handling when body does not exist in fetch client Feb 1, 2025
@soartec-lab soartec-lab requested a review from melloware February 1, 2025 06:55
@soartec-lab soartec-lab added enhancement New feature or request fetch Fetch client related issue bug Something isn't working labels Feb 1, 2025
@soartec-lab soartec-lab changed the title fix: Improved error handling when body does not exist in fetch client fix(fetch): Improved error handling when body does not exist in fetch client Feb 1, 2025
@melloware melloware merged commit 043c5bc into orval-labs:master Feb 1, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request fetch Fetch client related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

401 response with no body throws JSON parsing error when using fetch
2 participants