@@ -17,6 +17,7 @@ package coredata
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
@@ -49,8 +51,24 @@ type (
|
||||
}
|
||||
|
||||
CustomDomains []*CustomDomain
|
||||
|
||||
ErrCustomDomainNotFound struct {
|
||||
Identifier string
|
||||
}
|
||||
|
||||
ErrCustomDomainAlreadyExists struct {
|
||||
message string
|
||||
}
|
||||
)
|
||||
|
||||
func (e ErrCustomDomainNotFound) Error() string {
|
||||
return fmt.Sprintf("custom domain not found: %q", e.Identifier)
|
||||
}
|
||||
|
||||
func (e ErrCustomDomainAlreadyExists) Error() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
func NewCustomDomain(tenantID gid.TenantID, domain string) *CustomDomain {
|
||||
now := time.Now()
|
||||
return &CustomDomain{
|
||||
@@ -357,6 +375,14 @@ INSERT INTO custom_domains (
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "custom_domains_domain_key" {
|
||||
return &ErrCustomDomainAlreadyExists{
|
||||
message: fmt.Sprintf("custom domain with domain %q already exists", cd.Domain),
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("cannot insert custom domain: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user