Skip to content

ConnectError thrown through expressConnectMiddleware has invalid code&message #1582

@olereidar

Description

@olereidar

Describe the bug
Hello, I am using connect as a proxy to my server. I am experiencing that ConnectErrors thrown from server gets transformed into something else. Not sure if this is intentional or not.

For instance, I have this error on server:

// server throws this error:

ConnectError {
  name: 'ConnectError',
  rawMessage: 
    'Message validation failed: customer_account_id value does not match regex pattern `^([A-Z]{3}):([A-Za-z]+):([0-9ÆØÅæøåA-Za-z_\-]+)$`',
  code: 3,
  metadata: Headers {},
  details: [ ...],
  cause: undefined,
  message: 
    '[invalid_argument] Message validation failed: customer_account_id value does not match regex pattern `^([A-Z]{3}):([A-Za-z]+):([0-9ÆØÅæøåA-Za-z_\-]+)$`'
}

// client gets this error: 
ConnectError {
  name: 'ConnectError',
  rawMessage: 'HTTP 400',
  code: 13,
  metadata: Headers {},
  details: [],
  cause: undefined,
  message: '[internal] HTTP 400',
  line: 77,
  column: 10,
  sourceURL: 'http://localhost:3000/node_modules/.vite/deps/chunk-NKPO2XQB.js',
  stack:  ...
}

It seems like the error gets translated into a 400 bad request. I can find the error details in the error.metadata, but I find it strange that it gets transformed. Is it intentional?

To Reproduce
Throw a ConnectError som server. Use expressConnectMiddleware.

Environment (please complete the following information):

  • @connectrpc/connect-express: "2.0.4",
  • @connectrpc/connect-node: "2.0.4",
  • Node.js version: v22.13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions