Skip to content

Commit 979bdb8

Browse files
authored
Implement server OnError() hook (#46)
Example: rpcServer := proto.NewVideoServer(app.Rpc) rpcServer.OnError = func(r *http.Request, err *proto.WebRPCError) { ctx := r.Context() // Log error with request log httplog.LogEntrySetField(ctx context.Context, "webrpcError", err.Error()) // Report crucial DB errors to Sentry var pgErr *pgconn.PgError if errors.As(err, &pgErr) { // https://www.postgresql.org/docs/16/errcodes-appendix.html if strings.HasPrefix(pgErr.Code, "42") { sentry.CaptureException(err) } } // Add requestID to error message itself. rpcErr.Message = fmt.Sprintf("%s (requestID: %v)", rpcErr.Message, middleware.GetReqID(ctx)) // Hide error details from users in production. if app.Config.Environment.IsProduction() { rpcErr.Cause = "" } }
1 parent a5f5621 commit 979bdb8

File tree

3 files changed

+118
-40
lines changed

3 files changed

+118
-40
lines changed

_examples/golang-basics/example.gen.go

+57-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_examples/golang-imports/api.gen.go

+35-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)