Skip to content

[BUG][JAVA] ApiException does not include any HTTP response info in getMessage() #12205

@panargirakis

Description

@panargirakis
Description

The HTTP response code, response body or response headers are completely absent from the exception printout when an ApiException occurs making debugging very difficult.

This issue could instead be considered a feature request but I consider it a bug due to how severely it impacts the debugging/root cause analysis workflow.

This happens because ApiException.java class uses the default getMessage() method from super which only includes the message attribute.

openapi-generator version

Versions 5.4.0 and 6.0.0-beta exhibit this behavior.

OpenAPI declaration file content or url

Full schema here

Generation Details

Run the following script:

curl https://gist.githubusercontent.com/panargirakis/0d465f954f2c913ef3fc379f1b63da91/raw/0135da54dc950da698e8104bad88ed52af5a6aa6/ResSystem_Schema_2.1.0.yml -o ./latest_schema.yml
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v5.4.0 generate -i /local/latest_schema.yml -g java -o /local/
Related issues/PRs

None I am aware of.

Suggest a fix

Override getMessage() in ApiException.java similarly to:

public String getMessage() {
        return String.format("\nCode: %s\nMessage: %s\nResponseBody: %s\nResponseHeaders: %s\n",
                this.getCode(), super.getMessage(), this.getResponseBody(), this.getResponseHeaders().toString());
    }

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