Skip to content

How to receive ErrorDetails using Google's error_details.proto #581

Answered by timostamm
boan-anbo asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @boan-anbo,

with the following buf.gen.yaml:

version: v1
plugins:
  - plugin: buf.build/bufbuild/es
    opt: target=ts
    out: gen

Run the following command to generate the googleapis module, which includes error_details.proto:

npx buf generate buf.build/googleapis/googleapis

The new file gen/google/rpc/error_details_pb.ts will contain all proto messages for error details. One of them is google.rpc.LocalizedMessage, for error messages that are safe to return to the user.

Here is a function that finds a LocalizedMessage for the current locale from the error details:

import {ConnectError, connectErrorDetails} from "@bufbuild/connect-web";
import {LocalizedMessage} from "./gen/google/rp…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@boan-anbo
Comment options

Answer selected by boan-anbo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants