ts-proto icon indicating copy to clipboard operation
ts-proto copied to clipboard

Export better Error type for grpc-web

Open zlk89 opened this issue 2 years ago • 2 comments

See the output file here: https://github.com/stephenh/ts-proto/blob/e4351d4304be2d2ce7b95e74e2c5f2383d6754e5/integration/grpc-web/example.ts#L847-L850

It sets code and metadata into the Error object, but it would be great to export a better type for the Error object, so consumers can use the Error object more safely.

Right now we have to do something like this:

  try {
    return await client.method({ url });
  } catch (e) {
    if (e instanceof Error) {
      const grpcCode = "code" in e ? (e["code"] as number) : "unknown";
      console.log("grpcCode", grpcCode);
    }
  }

zlk89 avatar May 27 '22 18:05 zlk89

@zlk89 makes sense! If you want to submit a PR, that'd be great.

stephenh avatar May 27 '22 18:05 stephenh

This is fixed by #593

zakhenry avatar Aug 09 '22 00:08 zakhenry