2024-12-14 12:06:49 +00:00
|
|
|
package service_internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-12-18 03:12:13 +00:00
|
|
|
"errors"
|
|
|
|
|
2024-12-14 12:06:49 +00:00
|
|
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
2024-12-18 03:12:13 +00:00
|
|
|
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
|
2024-12-18 03:12:13 +00:00
|
|
|
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(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|