maps-service/pkg/service_internal/service_internal.go

31 lines
622 B
Go
Raw Normal View History

2024-12-14 12:06:49 +00:00
package service_internal
import (
"context"
"errors"
2024-12-14 12:06:49 +00:00
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
2024-12-14 12:06:49 +00:00
"github.com/nats-io/nats.go"
)
type Service struct {
DB datastore.Datastore
Nats nats.JetStreamContext
}
// yay duplicate code
func (svc *Service) NewError(ctx context.Context, err error) *internal.ErrorStatusCode {
status := 500
if errors.Is(err, datastore.ErrNotExist) {
status = 404
}
2024-12-14 12:06:49 +00:00
return &internal.ErrorStatusCode{
StatusCode: status,
Response: internal.Error{
Code: int64(status),
Message: err.Error(),
},
}
}