auth-api: deal with errors properly in NewService

This commit is contained in:
Pascal Bleser
2026-02-04 11:57:27 +01:00
parent f002d3cac7
commit ab1930a676
2 changed files with 7 additions and 4 deletions

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)

View File

@@ -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 {