OpenAPITools / OpenAPITools/openapi-generator
[REQ] Feature Request Description
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
In javascript/typescript throwing anything but an error is considered an antipattern. Only errors should be thrown because:
- Only errors can provide a reliable stacktraces
- Makes error handling easier, since 99.99% of caught "things" will have a common interface
{ message: string }.
Right now typescript-fetch throws a bare Response which is undesirable.
https://github.com/OpenAPITools/openapi-generator/blob/60b29e1f8e267e90d4d81f30d3fb3fe69161e59b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache#L38-L42
Describe the solution you'd like
Typescript-fetch should throw a custom error in which the response is just a property, just like it does with RequiredError.
https://github.com/OpenAPITools/openapi-generator/blob/60b29e1f8e267e90d4d81f30d3fb3fe69161e59b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache#L104-L109
E.g.
const response = await this.fetchApi(url, init);
if (response.status >= 200 && response.status < 300) {
return response;
}
throw new ResponseError(response, 'Response returned an error code');
...
export class ResponseError extends Error {
name: "ResponseError" = "ResponseError";
constructor(public response: Response, msg?: string) {
super(msg);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache around lines 38-42, then compare the RequiredError implementation around lines 104-109. Done means typescript-fetch throws a custom ResponseError containing the Response instead of throwing the bare response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100