auth-api: deal with errors properly in NewService

This commit is contained in:
Pascal Bleser committed 2026-07-09 14:15:52 +02:00
1 parent 82c28e4735
commit bfbded45e2
2 files changed
+7 -4

No files matched your search

+4 -1
View File
@@ -32,7 +32,7 @@ func Server(opts ...Option) (http.Service, error) {
return http.Service{}, fmt.Errorf("could not initialize http service: %w", err)
}
handle := svc.NewService(
handle, err := svc.NewService(
svc.Logger(options.Logger),
svc.Config(options.Config),
svc.Metrics(options.Metrics),
@@ -47,6 +47,9 @@ func Server(opts ...Option) (http.Service, error) {
opencloudmiddleware.Logger(options.Logger),
),
)
if err != nil {
return http.Service{}, err
}
{
handle = svc.NewInstrument(handle, options.Metrics)
@@ -29,7 +29,7 @@ type Service interface {
}
// NewService returns a service implementation for Service.
func NewService(opts ...Option) Service {
func NewService(opts ...Option) (Service, error) {
options := newOptions(opts...)
m := chi.NewMux()
@@ -47,7 +47,7 @@ func NewService(opts ...Option) Service {
svc, err := NewAuthenticationApi(options.Config, &options.Logger, options.Metrics, options.TraceProvider, m)
if err != nil {
panic(err) // TODO p.bleser what to do when we encounter an error in a NewService() ?
return nil, err
}
m.Route(options.Config.HTTP.Root, func(r chi.Router) {
@@ -59,7 +59,7 @@ func NewService(opts ...Option) Service {
return nil
})
return svc
return svc, nil
}
type AuthenticationApi struct {