From 7c071cc0c2ee6d6f626530df3bf1c020e0ff1237 Mon Sep 17 00:00:00 2001 From: Cassandra Coyle Date: Tue, 12 Dec 2023 17:17:12 -0600 Subject: [PATCH] update README Signed-off-by: Cassandra Coyle --- errors/README.md | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/errors/README.md b/errors/README.md index 37f4fb1..0e2e9a6 100644 --- a/errors/README.md +++ b/errors/README.md @@ -4,24 +4,31 @@ The standardizing of errors to be used in Dapr based on the gRPC Richer Error Mo ## Usage +Define the error ```go import kitErrors "github.com/dapr/kit/errors" // Define error in dapr pkg/api/_errors.go -func PubSubNotFound(pubsubName string, pubsubType string, metadata map[string]string) error { -message := fmt.Sprintf("pubsub %s is not found", pubsubName) - -return kitErrors.New( -grpcCodes.NotFound, -http.StatusBadRequest, -message, -fmt.Sprintf("%s%s", kitErrors.CodePrefixPubSub, kitErrors.CodeNotFound), -). -WithErrorInfo(kitErrors.CodePrefixPubSub+kitErrors.CodeNotFound, metadata). -WithResourceInfo(pubsubType, pubsubName, "", message) +func PubSubNotFound(name string, pubsubType string, metadata map[string]string) error { + message := fmt.Sprintf("pubsub %s is not found", name) + + return kitErrors.NewBuilder( + grpcCodes.NotFound, + http.StatusBadRequest, + message, + kitErrors.CodePrefixPubSub+kitErrors.CodeNotFound, + ). + WithErrorInfo(kitErrors.CodePrefixPubSub+kitErrors.CodeNotFound, metadata). + WithResourceInfo(pubsubType, name, "", message). + Build() } +``` + +Use the error +```go +import apiErrors "github.com/dapr/dapr/pkg/api/errors" // Use error in dapr and pass in relevant information -err = errutil.PubSubNotFound(pubsubName, pubsubType, metadata) +err = apiErrors.PubSubNotFound(pubsubName, pubsubType, metadata) ```