Skip to content

Commit

Permalink
BED-5066: resolve TS errors
Browse files Browse the repository at this point in the history
Raise name error on duplicate SSO slug
  • Loading branch information
wes-mil committed Dec 20, 2024
1 parent c4947e5 commit dbbc6f6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions cmd/api/src/database/sso_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (s *BloodhoundDB) CreateSSOProvider(ctx context.Context, name string, authP
if result.Error != nil {
if strings.Contains(result.Error.Error(), "duplicate key value violates unique constraint \"sso_providers_name_key\"") {
return fmt.Errorf("%w: %v", ErrDuplicateSSOProviderName, tx.Error)
} else if strings.Contains(result.Error.Error(), "duplicate key value violates unique constraint \"sso_providers_slug_key\"") {
return fmt.Errorf("%w: %v", ErrDuplicateSSOProviderName, tx.Error)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ const CreateUserForm: React.FC<{
if (error.response?.data?.errors[0]?.message.toLowerCase().includes('principal name')) {
setError('principal', { type: 'custom', message: 'Principal name is already in use.' });
} else {
setError('generic', { type: 'custom', message: `A conflict has occured.` });
setError('root.generic', { type: 'custom', message: `A conflict has occured.` });
}
} else {
setError('generic', { type: 'custom', message: 'An unexpected error occurred. Please try again.' });
setError('root.generic', {
type: 'custom',
message: 'An unexpected error occurred. Please try again.',
});
}
}
}, [authenticationMethod, setValue, error, setError]);
Expand Down Expand Up @@ -349,9 +352,9 @@ const CreateUserForm: React.FC<{
)}
/>
</Grid>
{!!errors.generic && (
{!!errors.root?.generic && (
<Grid item xs={12}>
<Alert severity='error'>{errors.generic.message}</Alert>
<Alert severity='error'>{errors.root.generic.message}</Alert>
</Grid>
)}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@ const UpdateUserFormInner: React.FC<{
if (error.response?.data?.errors[0]?.message.toLowerCase().includes('principal name')) {
setError('principal', { type: 'custom', message: 'Principal name is already in use.' });
} else {
setError('generic', { type: 'custom', message: `A conflict has occured.` });
setError('root.generic', { type: 'custom', message: `A conflict has occured.` });
}
} else {
setError('generic', { type: 'custom', message: 'An unexpected error occurred. Please try again.' });
setError('root.generic', {
type: 'custom',
message: 'An unexpected error occurred. Please try again.',
});
}
}
}, [authenticationMethod, setValue, error, setError]);
Expand Down Expand Up @@ -372,9 +375,9 @@ const UpdateUserFormInner: React.FC<{
)}
/>
</Grid>
{!!errors.generic && (
{!!errors.root?.generic && (
<Grid item xs={12}>
<Alert severity='error'>{errors.generic.message}</Alert>
<Alert severity='error'>{errors.root.generic.message}</Alert>
</Grid>
)}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const UpsertOIDCProviderForm: FC<{
if (error.response?.data?.errors[0]?.message.toLowerCase().includes('sso provider name')) {
setError('name', { type: 'custom', message: 'SSO Provider Name is already in use.' });
} else {
setError('generic', {
setError('root.generic', {
type: 'custom',
message: 'A conflict has occured.',
});
}
} else {
setError('generic', {
setError('root.generic', {
type: 'custom',
message: `Unable to ${oldSSOProvider ? 'update' : 'create new'} OIDC Provider configuration. Please try again.`,
});
Expand Down Expand Up @@ -134,9 +134,9 @@ const UpsertOIDCProviderForm: FC<{
)}
/>
</Grid>
{!!errors.generic && (
{!!errors.root?.generic && (
<Grid item xs={12}>
<Alert severity='error'>{errors.generic.message}</Alert>
<Alert severity='error'>{errors.root.generic.message}</Alert>
</Grid>
)}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ const UpsertSAMLProviderForm: FC<{
if (error.response?.data?.errors[0]?.message.toLowerCase().includes('sso provider name')) {
setError('name', { type: 'custom', message: 'SSO Provider Name is already in use.' });
} else {
setError('generic', {
setError('root.generic', {
type: 'custom',
message: `A conflict has occured.`,
});
}
} else {
setError('generic', {
setError('root.generic', {
type: 'custom',
message: `Unable to ${oldSSOProvider ? 'update' : 'create new'} SAML Provider configuration. Please try again.`,
});
Expand Down Expand Up @@ -147,9 +147,9 @@ const UpsertSAMLProviderForm: FC<{
: 'Upload the Metadata file provided by your SAML Provider'}
</FormHelperText>
</Grid>
{!!errors.generic && (
{!!errors.root?.generic && (
<Grid item xs={12}>
<Alert severity='error'>{errors.generic.message}</Alert>
<Alert severity='error'>{errors.root.generic.message}</Alert>
</Grid>
)}
</Grid>
Expand Down

0 comments on commit dbbc6f6

Please sign in to comment.