From c02f845ecb1e6482164f8029ba854f82aff317c2 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Wed, 27 Oct 2021 19:39:18 +0200 Subject: [PATCH] AuthController: Return 409 Conflict when user already exists The previously used HTTP error 400 'Bad Request' is not really applicable here, as the client did not send a malformed message. Signed-off-by: David Mehren --- src/api/private/auth/auth.controller.ts | 3 ++- test/private-api/auth.e2e-spec.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/private/auth/auth.controller.ts b/src/api/private/auth/auth.controller.ts index 334a1d29b..b2f0b3bc7 100644 --- a/src/api/private/auth/auth.controller.ts +++ b/src/api/private/auth/auth.controller.ts @@ -6,6 +6,7 @@ import { BadRequestException, Body, + ConflictException, Controller, Delete, NotFoundException, @@ -56,7 +57,7 @@ export class AuthController { return; } catch (e) { if (e instanceof AlreadyInDBError) { - throw new BadRequestException(e.message); + throw new ConflictException(e.message); } throw e; } diff --git a/test/private-api/auth.e2e-spec.ts b/test/private-api/auth.e2e-spec.ts index 7df133331..c1976f219 100644 --- a/test/private-api/auth.e2e-spec.ts +++ b/test/private-api/auth.e2e-spec.ts @@ -75,7 +75,7 @@ describe('Auth', () => { .post('/api/private/auth/local') .set('Content-Type', 'application/json') .send(JSON.stringify(registrationDto)) - .expect(400); + .expect(409); }); it('when registration is disabled', async () => { testSetup.configService.get('authConfig').local.enableRegister = false;