OpenAPITools / OpenAPITools/openapi-generator

[REQ] Typescript (experimental) - pass response body in ApiException

Open
#11,100 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
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.

When ApiException<T> is thrown is does not contain the response body
Having the response body is very useful when catching errors (especially when the destination server added more details about the error in the response body)

Describe the solution you'd like

I suggest to add response.getBodyAsAny() every time we are creating ApiException
For instance, instead:

throw new ApiException<undefined>(response.httpStatusCode, "Bad Request.", undefined, response.headers);

we will generate:

throw new ApiException(response.httpStatusCode, "Bad Request.", await response.getBodyAsAny(), response.headers);
Describe alternatives you've considered

For now, in order to address the problem we are running a this post generator script:

import * as replace from 'replace-in-file'

replace.sync({
    files: 'src/generated/apis/**',
    from: /new ApiException<undefined>/g,
    to: 'new ApiException',
    countMatches: true,
  });

replace.sync({
    files: 'src/generated/apis/**',
    from: /undefined, response.headers/g,
    to: 'await response.getBodyAsAny(), response.headers',
    countMatches: true,
});

Even though it does the trick, this is obviously a hack and it will be better if this will be part of the original generated code

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the TypeScript experimental generator templates that emit ApiException calls for files under src/generated/apis/**. Trace how response.getBodyAsAny() and the response body are handled before the exception is created. Done means generated clients pass the response body consistently and the generated TypeScript code still compiles and passes its available tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.