Skip to content

Commit

Permalink
Return 400 for duplicate name error
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed May 13, 2021
1 parent f271882 commit 931f54a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { SavedObjectsClientContract, ElasticsearchClient } from 'src/core/s
import { esKuery } from '../../../../../../src/plugins/data/server';
import type { ESSearchResponse as SearchResponse } from '../../../../../../typings/elasticsearch';
import type { EnrollmentAPIKey, FleetServerEnrollmentAPIKey } from '../../types';
import { IngestManagerError } from '../../errors';
import { ENROLLMENT_API_KEYS_INDEX } from '../../constants';
import { agentPolicyService } from '../agent_policy';
import { escapeSearchQueryPhrase } from '../saved_object';
Expand Down Expand Up @@ -177,7 +178,7 @@ export async function generateEnrollmentAPIKey(
k.name?.replace(providedKeyName, '').trim().match(uuidRegex)
)
) {
throw new Error(
throw new IngestManagerError(
i18n.translate('xpack.fleet.serverError.enrollmentKeyDuplicate', {
defaultMessage:
'An enrollment key named {providedKeyName} already exists for agent policy {agentPolicyId}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ export default function (providerContext: FtrProviderContext) {
policy_id: 'policy1',
name: 'something',
})
.expect(500);
.expect(400);

expect(noSpacesDupe).to.eql({
statusCode: 500,
error: 'Internal Server Error',
statusCode: 400,
error: 'Bad Request',
message: 'An enrollment key named something already exists for agent policy policy1',
});

Expand All @@ -156,10 +156,10 @@ export default function (providerContext: FtrProviderContext) {
policy_id: 'policy1',
name: 'something else',
})
.expect(500);
.expect(400);
expect(hasSpacesDupe).to.eql({
statusCode: 500,
error: 'Internal Server Error',
statusCode: 400,
error: 'Bad Request',
message: 'An enrollment key named something else already exists for agent policy policy1',
});
});
Expand Down

0 comments on commit 931f54a

Please sign in to comment.