Skip to content

Commit

Permalink
Merge pull request #10 from izumin5210/izumin5210/readme
Browse files Browse the repository at this point in the history
Improve readme
  • Loading branch information
izumin5210 authored Oct 15, 2017
2 parents 97063a2 + 0b0a456 commit 0e7f9b1
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,27 @@ func main() {
panic(err)
}

errorHandlers := []grpcerrors.ErrorHandlerFunc{
grpcerrors.WithNotWrappedErrorHandler(func(c context.Context, err error) error {
// WithNotWrappedErrorHandler handles an error not wrapped with `*apperror.Error`.
// A handler function should wrap received error with `*apperror.Error`.
return apperrors.WithStatusCode(err, CodeNotWrapped)
}),
grpcerrors.WithReportableErrorHandler(func(c context.Context, err *apperrors.Error) error {
// WithReportableErrorHandler handles an erorr annotated with the reportability.
// You reports to an external service if necessary.
// And you can attach request contexts to error reports.
return err
}),
grpcerrors.WithStatusCodeMap(grpcCodeByYourCode),
}

s := grpc.NewServer(
grpc_middleware.WithStreamServerChain(
grpcerrors.StreamServerInterceptor(
grpcerrors.WithNotWrappedErrorHandler(func(err error) error {
return apperrors.WithStatusCode(err, CodeNotWrapped)
}),
grpcerrors.WithReportableErrorHandler(func(err *apperrors.Error) error {
switch err.StatusCode {
case CodeYourCustomError:
// Report your custom errors
case CodeNotWrapped:
// Report not wrapped errors
default:
// Report errors
}
return err
}),
grpcerrors.WithStatusCodeMapper(grpcCodeByYourCode),
),
grpcerrors.StreamServerInterceptor(errorHandlers...),
),
grpc_middleware.WithUnaryServerChain(
grpcerrors.UnaryServerInterceptor(
// Write your error handlers for an unary server
),
grpcerrors.UnaryServerInterceptor(errorHandlers...),
),
)

Expand Down

0 comments on commit 0e7f9b1

Please # to comment.