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 <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-10-27 19:39:18 +02:00
parent 3560d82c44
commit 5a16047f50
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 3 additions and 2 deletions

View file

@ -6,6 +6,7 @@
import { import {
BadRequestException, BadRequestException,
Body, Body,
ConflictException,
Controller, Controller,
Delete, Delete,
NotFoundException, NotFoundException,
@ -56,7 +57,7 @@ export class AuthController {
return; return;
} catch (e) { } catch (e) {
if (e instanceof AlreadyInDBError) { if (e instanceof AlreadyInDBError) {
throw new BadRequestException(e.message); throw new ConflictException(e.message);
} }
throw e; throw e;
} }

View file

@ -75,7 +75,7 @@ describe('Auth', () => {
.post('/api/private/auth/local') .post('/api/private/auth/local')
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')
.send(JSON.stringify(registrationDto)) .send(JSON.stringify(registrationDto))
.expect(400); .expect(409);
}); });
it('when registration is disabled', async () => { it('when registration is disabled', async () => {
testSetup.configService.get('authConfig').local.enableRegister = false; testSetup.configService.get('authConfig').local.enableRegister = false;