Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
Signed-off-by: Cassandra Coyle <[email protected]>
  • Loading branch information
cicoyle committed Dec 12, 2023
1 parent 993b20f commit 7c071cc
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions errors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<building_block>_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)

```

0 comments on commit 7c071cc

Please sign in to comment.