thrift-typescript icon indicating copy to clipboard operation
thrift-typescript copied to clipboard

No way to distinguish exception objects

Open markdoliner opened this issue 5 years ago • 1 comments

I have a service that can throw two different exceptions:

service Whatever {
  exception ExceptionA {}
  exception ExceptionB {}
  void doSomething() throws (1: ExceptionA exceptionA, 2: ExceptionB exceptionB)
}

When the server throws one of the exceptions there's no way for the client to determine which exception was thrown. e.constructor.name is simply "Object"

I'm running thrift-typescript with --target thrift-server.

One workaround is to run thrift-typescript --withNameField, in which case exceptions can be distinguished by checking if (e.__name === 'ExceptionA'), but that's not ideal.

https://github.com/creditkarma/thrift-typescript/issues/178 is related.

markdoliner avatar Jan 10 '20 21:01 markdoliner

I posted a PR that addresses this by changing the client to return instances of our classes.

markdoliner-doma avatar Jun 01 '20 15:06 markdoliner-doma