Skip to content

Commit e8d1141

Browse files
committed
Return specific handle conflict
1 parent 565cfe2 commit e8d1141

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎scripts/orbit-slice1-tests.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,37 @@ let firstCredentialToken = '';
471471
assert.ok(!managedText.includes('token'));
472472
});
473473

474+
test('duplicate handles return a specific conflict without consuming the registration code', async () => {
475+
const created = await postJson(
476+
'/v1/agent-registration-codes',
477+
{},
478+
authenticatedHeaders(ownerCookies, true),
479+
NOW + 45,
480+
);
481+
assert.equal(created.status, 201, await created.clone().text());
482+
const createdBody = await created.json() as { registrationCode: { token: string } };
483+
484+
const duplicate = await postJson('/v1/agent/register', {
485+
code: createdBody.registrationCode.token,
486+
handle: 'SELENE-TEST-AGENT',
487+
bio: 'Bu handle çakışmalı.',
488+
}, {}, NOW + 46);
489+
assert.equal(duplicate.status, 409, await duplicate.clone().text());
490+
const duplicateBody = await duplicate.json() as { error: { code: string; message: string } };
491+
assert.equal(duplicateBody.error.code, 'handle_unavailable');
492+
assert.equal(
493+
duplicateBody.error.message,
494+
'Bu handle zaten kullanımda; aynı kayıt koduyla başka bir handle dene.',
495+
);
496+
497+
const retried = await postJson('/v1/agent/register', {
498+
code: createdBody.registrationCode.token,
499+
handle: 'owner-retry-agent',
500+
bio: 'Aynı kodla başarılı tekrar denemesi.',
501+
}, {}, NOW + 47);
502+
assert.equal(retried.status, 201, await retried.clone().text());
503+
});
504+
474505
test('only the agent credential can edit identity fields', async () => {
475506
const sponsorAttempt = await patchJson(`/v1/agents/${sponsoredAgentId}`, {
476507
bio: 'Sponsor rewrite.',

‎src/server/http/api.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,13 @@ export async function handleApiRequest(
24172417
requestId,
24182418
), 409);
24192419
}
2420+
if (/UNIQUE constraint failed:\s*agents\.handle_normalized\b/iu.test(message)) {
2421+
return json(createErrorEnvelope(
2422+
'handle_unavailable',
2423+
'Bu handle zaten kullanımda; aynı kayıt koduyla başka bir handle dene.',
2424+
requestId,
2425+
), 409);
2426+
}
24202427
if (/posts_created BETWEEN 0 AND 5|replies_created BETWEEN 0 AND 30/u.test(message)) {
24212428
return json(createErrorEnvelope(
24222429
'daily_quota_exceeded',

0 commit comments

Comments
 (0)