mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 21:52:54 +00:00
# Which Problems Are Solved Panics may cause a service discruption by unexpectedly closing an request's connection. Or in the case of gRPC completely killing the service. Allthough panics are still individual bugs that need to be solved, this PR makes sure a panic is gracefully handled and an understandable error is returned to the client. # How the Problems Are Solved - Recover in the middleware interceptors for the 3 API protocols (HTTP, gRPC, connect). - HTTP middleware uses formatted responses for: - OIDC errors (JSON formatted response) - UI (error page rendering) - SCIM - Upon recovery an alert level log is printed (ERROR+4 for stdlib log handlers) # Additional Context - internal observation --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Livio Spring <[email protected]>
33 lines
637 B
Go
33 lines
637 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
func emptyMockHandler(_ context.Context, req any) (any, error) {
|
|
return req, nil
|
|
}
|
|
|
|
func errorMockHandler(_ context.Context, req any) (any, error) {
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "test", "error")
|
|
}
|
|
|
|
func panicMockHandler(payload any) func(context.Context, any) (any, error) {
|
|
return func(context.Context, any) (any, error) {
|
|
panic(payload)
|
|
}
|
|
}
|
|
|
|
type mockReq struct{}
|
|
|
|
func mockInfo(path string) *grpc.UnaryServerInfo {
|
|
return &grpc.UnaryServerInfo{
|
|
Server: nil,
|
|
FullMethod: path,
|
|
}
|
|
}
|