GOLANG_DIGEST Telegram 120
Advanced gRPC Error Usage

https://jbrandhorst.com/post/grpc-errors/

Коротенькая статья о том, как с помощью пакета status добавлять произвольные метаданные к ошибкам. Это бывает очень удобно при разборе и обработке ошибок между сервисами.

Пример:

st := status.New(codes.InvalidArgument, "invalid username")
desc := "The username must only contain alphanumeric characters"
v := &errdetails.BadRequest_FieldViolation{
Field: "username",
Description: desc,
}
br := &errdetails.BadRequest{}
br.FieldViolations = append(br.FieldViolations, v)
st, err := st.WithDetails(br)
if err != nil {
// If this errored, it will always error
// here, so better panic so we can figure
// out why than have this silently passing.
panic(fmt.Sprintf("Unexpected error attaching metadata: %v", err))
}
return st.Err()


————
За ссылку спасибо @ekostogorov

#grpc #article
👍92



tgoop.com/golang_digest/120
Create:
Last Update:

Advanced gRPC Error Usage

https://jbrandhorst.com/post/grpc-errors/

Коротенькая статья о том, как с помощью пакета status добавлять произвольные метаданные к ошибкам. Это бывает очень удобно при разборе и обработке ошибок между сервисами.

Пример:

st := status.New(codes.InvalidArgument, "invalid username")
desc := "The username must only contain alphanumeric characters"
v := &errdetails.BadRequest_FieldViolation{
Field: "username",
Description: desc,
}
br := &errdetails.BadRequest{}
br.FieldViolations = append(br.FieldViolations, v)
st, err := st.WithDetails(br)
if err != nil {
// If this errored, it will always error
// here, so better panic so we can figure
// out why than have this silently passing.
panic(fmt.Sprintf("Unexpected error attaching metadata: %v", err))
}
return st.Err()


————
За ссылку спасибо @ekostogorov

#grpc #article

BY Golang Дайджест


Share with your friend now:
tgoop.com/golang_digest/120

View MORE
Open in Telegram


Telegram News

Date: |

5Telegram Channel avatar size/dimensions Activate up to 20 bots A Telegram channel is used for various purposes, from sharing helpful content to implementing a business strategy. In addition, you can use your channel to build and improve your company image, boost your sales, make profits, enhance customer loyalty, and more. Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. As five out of seven counts were serious, Hui sentenced Ng to six years and six months in jail.
from us


Telegram Golang Дайджест
FROM American