mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 16:54:25 -05:00
NotesController: Handle new errors
Handle the AlreadyInDB and PermissionsUpdateInconsistent errors and correctly show them to the api user as BadRequest errors. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
13955aebe5
commit
e538056252
1 changed files with 19 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
BadRequestException,
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
|
@ -18,7 +19,11 @@ import {
|
||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { NotInDBError } from '../../../errors/errors';
|
import {
|
||||||
|
AlreadyInDBError,
|
||||||
|
NotInDBError,
|
||||||
|
PermissionsUpdateInconsistentError,
|
||||||
|
} from '../../../errors/errors';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
import {
|
import {
|
||||||
NotePermissionsDto,
|
NotePermissionsDto,
|
||||||
|
@ -100,9 +105,16 @@ export class NotesController {
|
||||||
throw new UnauthorizedException('Creating note denied!');
|
throw new UnauthorizedException('Creating note denied!');
|
||||||
}
|
}
|
||||||
this.logger.debug('Got raw markdown:\n' + text, 'createNamedNote');
|
this.logger.debug('Got raw markdown:\n' + text, 'createNamedNote');
|
||||||
|
try {
|
||||||
return this.noteService.toNoteDto(
|
return this.noteService.toNoteDto(
|
||||||
await this.noteService.createNote(text, noteAlias, req.user),
|
await this.noteService.createNote(text, noteAlias, req.user),
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AlreadyInDBError) {
|
||||||
|
throw new BadRequestException(e.message);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(TokenAuthGuard)
|
@UseGuards(TokenAuthGuard)
|
||||||
|
@ -191,6 +203,9 @@ export class NotesController {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
throw new NotFoundException(e.message);
|
throw new NotFoundException(e.message);
|
||||||
}
|
}
|
||||||
|
if (e instanceof PermissionsUpdateInconsistentError) {
|
||||||
|
throw new BadRequestException(e.message);
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue