Skip to content

ResponseError provides root_cause of an exception #1452

@mshustov

Description

@mshustov

🚀 Feature Proposal

To refactor ResponseError.toString method format to include root_cause details provided by Elasticsearch server.

Motivation

Applications often log a caught exceptions without additional effort for serialization.
If you log ResponseError

try {
  await client.search(...);
} catch (e) {
  console.error(e)
}

you don't get an original error_cause:

    ResponseError: illegal_argument_exception
        at onBody (.../node_modules/@elastic/elasticsearch/lib/Transport.js:337:23)
        at IncomingMessage.onEnd (.../node_modules/@elastic/elasticsearch/lib/Transport.js:264:11)
        at IncomingMessage.emit (events.js:327:22)
        at endReadableNT (internal/streams/readable.js:1327:12)
        at processTicksAndRejections (internal/process/task_queues.js:80:21) {
      meta: {
        body: { error: [Object], status: 400 },
        statusCode: 400,
        headers: {
          'content-type': 'application/json;charset=utf-8',
          'content-length': '367'
        },
        meta: {
          context: null,
          request: [Object],
          name: 'elasticsearch-js',
          connection: [Object],
          attempts: 0,
          aborted: false
        }
      }
    }

that makes debugging quite painful.

To makeerror.message actionalbe, it should include the root_cause provided by Elasticsearch server: ResponseError: [illegal_argument_exception]. caused by [{ type: "...", reason: "..." }]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions