Fix 5xx when saml config already exist
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -308,6 +308,16 @@ func (e *ErrSAMLAuthenticationRequired) Error() string {
|
||||
return fmt.Sprintf("SAML authentication required: %s", e.Reason)
|
||||
}
|
||||
|
||||
type ErrSAMLConfigurationEmailDomainAlreadyExists struct{ EmailDomain string }
|
||||
|
||||
func NewSAMLConfigurationEmailDomainAlreadyExistsError(emailDomain string) error {
|
||||
return &ErrSAMLConfigurationEmailDomainAlreadyExists{EmailDomain: emailDomain}
|
||||
}
|
||||
|
||||
func (e ErrSAMLConfigurationEmailDomainAlreadyExists) Error() string {
|
||||
return fmt.Sprintf("SAML configuration email domain %q already exists", e.EmailDomain)
|
||||
}
|
||||
|
||||
// TenantAccessError is used by API recovery middleware to translate authorization/tenant failures
|
||||
// into a consistent client-facing error response.
|
||||
//
|
||||
|
||||
@@ -1069,6 +1069,10 @@ func (s OrganizationService) CreateSAMLConfiguration(
|
||||
|
||||
err = config.Insert(ctx, tx, scope)
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceAlreadyExists) {
|
||||
return NewSAMLConfigurationEmailDomainAlreadyExistsError(req.EmailDomain)
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert saml configuration: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user