Skip to content

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

@guysegal

Description

@guysegal

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions