Skip to content

[typescript-fetch]: use ReponseError instead of throwing a response (#10477) - #10478

Merged
macjohnny merged 1 commit into
OpenAPITools:masterfrom
javier-garcia-meteologica:typescript-fetch_response_error
Apr 4, 2022
Merged

[typescript-fetch]: use ReponseError instead of throwing a response (#10477)#10478
macjohnny merged 1 commit into
OpenAPITools:masterfrom
javier-garcia-meteologica:typescript-fetch_response_error

Conversation

@javier-garcia-meteologica

Copy link
Copy Markdown
Contributor

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov

@macjohnny

Copy link
Copy Markdown
Member

Thanks for your contribution.
Since this is a breaking change, please file against the 6.0 branch.
@amakhrov what is your opinion here? Should we introduce an option?

@javier-garcia-meteologica
javier-garcia-meteologica force-pushed the typescript-fetch_response_error branch from b6b93c9 to 1416e84 Compare September 28, 2021 17:37
@javier-garcia-meteologica
javier-garcia-meteologica changed the base branch from master to 6.0.x September 28, 2021 17:37
@amakhrov

Copy link
Copy Markdown
Contributor

Should we introduce an option?

I don't think so. Migrating existing code should be trivial enough.

}
};

export class ResponseError extends Error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this comes with some gotchas and generally won't work if your TS compile target is es5.

e.g. see https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work

@javier-garcia-meteologica javier-garcia-meteologica Sep 29, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a workaround, you can match by error name if the code needs to be compiled to es5

if (err.name === 'ResponseError') {
   ...
}

@mkusaka

mkusaka commented Apr 4, 2022

Copy link
Copy Markdown
Contributor

@macjohnny @amakhrov Is there any possibility this change will be included in version 6.0?
Currently, it seems that this pr is not included to 6.0 milestone.
Thanks.

@macjohnny

Copy link
Copy Markdown
Member

@amakhrov are you fine with this change?

@amakhrov

amakhrov commented Apr 4, 2022

Copy link
Copy Markdown
Contributor

@macjohnny yes, it looks reasonable, and is definitely better than throwing an arbitrary response object

@macjohnny
macjohnny changed the base branch from 6.0.x to master April 4, 2022 18:31
@macjohnny
macjohnny merged commit e8e1f6b into OpenAPITools:master Apr 4, 2022
@macjohnny macjohnny added this to the 6.0.0 milestone Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants